473,769 Members | 6,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Graceful disconnection from server

Hi, I am writing an terminal app that would allow you to connect to POP3
server and receive mail data in raw format. Now the POP3 server expects a
graceful disconnection by sending a "quit\r\n" command to it. The server then
replies you with a "+OK ... Goodbye" message.

Now I have a code as follows for the disconnect button:---
<pre>
private void btnDisconnect_C lick(object sender, System.EventArg s e)
{
if (serverSock != null)
{
if (serverSock.Con nected)
{
Send(serverSock , "quit\r\n") ;
sendDone.WaitOn e();
serverSock.Shut down(SocketShut down.Both);
serverSock.Clos e();
serverSock = null;
}
}
}
</pre>

Now the problem arises when this code executes. By the time the "quit\r\n"
command is sent to the server and the server sends a response message, the
socket object is already null and an Object Already disposed exception
arises..
Is there anything I can do to make the system wait asynchronously before the
socket is closed ???
Nov 16 '05 #1
1 1737
Set a class field indicating that you have sent the quit command. Move the
socket.Close() call, and other cleanup code, into a separate method (or
try/catch/finally block or a using block). In the method where you are
receiving your data,test for the field you set. If the field is set, and
the received bytes are OK, then call your cleanup method.

HTH

DalePres
MCAD, MCDBA, MCSE

"Mainak Sarcar" <Ma**********@d iscussions.micr osoft.com> wrote in message
news:B5******** *************** ***********@mic rosoft.com...
Hi, I am writing an terminal app that would allow you to connect to POP3
server and receive mail data in raw format. Now the POP3 server expects a
graceful disconnection by sending a "quit\r\n" command to it. The server
then
replies you with a "+OK ... Goodbye" message.

Now I have a code as follows for the disconnect button:---
<pre>
private void btnDisconnect_C lick(object sender, System.EventArg s e)
{
if (serverSock != null)
{
if (serverSock.Con nected)
{
Send(serverSock , "quit\r\n") ;
sendDone.WaitOn e();
serverSock.Shut down(SocketShut down.Both);
serverSock.Clos e();
serverSock = null;
}
}
}
</pre>

Now the problem arises when this code executes. By the time the "quit\r\n"
command is sent to the server and the server sends a response message, the
socket object is already null and an Object Already disposed exception
arises..
Is there anything I can do to make the system wait asynchronously before
the
socket is closed ???

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
977
by: Dirk Reske | last post by:
Hello, I have a Tcp Server and a client. all works fine, but how can the server detect, if a client has disconnected? i tried: while(true) { input = reader.ReadLine(); //the stream reader over the
5
16947
by: Vijay | last post by:
Hi all, i have TCP client server application written in C# using async socket methods, eg BeginReceive(), BeginEnd() etc server is continuesly running in the background, client connect to server and recives data from server. If server application shuts down client immedeatly recieves disconnection or exception, but im not able to detect if some body removed network cable of node , where server is running. Client continuesly waits for...
2
999
by: Marty | last post by:
Hi, I have a server that handle many client connection. In the case that the server try to send a message to a client. When the server is doing the mySocket.send(myMessage) and the client connection is already broken, what is the best way to handle this? Exception raising cost very much in time, does catching only like this code sample is doing is good?
9
5574
by: timor.super | last post by:
Hi group, I've written a client/server application, using the dotnet sockets. In my server, I have a thread waiting for messages with : ret = currSocket.Receive(buffer, 1024, SocketFlags.None); When the client exits, I close the socket with a specific message (like "end") and the thread terminate in a proper manner, but If my client crashes, the server is still waiting for receiving data, and
4
8288
by: Reshmi Jacob | last post by:
Hi I am facing this error while working with a database, about 40-50 persons are using this DB. I searched thru the sites to refer these error. They are saying t look into ALERT.LOG. I searched the entire server but couldn't find ALERT.LOG. Can any body help in finding this file??? Also, why this happens??? In the server, I have One database, 2 Users, 1 Listener, 1 Service Name. Anybody Help..........
2
4266
by: csgonan | last post by:
I have a new 64 bit apache 2.2.4 server on Solaris 10 with openssl 0.9.8e. When I DO NOT have the ssl.conf file included and I "apachectl graceful" to apache, all my processes that are gracefully shutdown are shown by a dash (-). When I have the Include line for the ssl.conf file uncommented, the number of Gs never changes, like it is locked in the graceful shutdown. I have prefork compiled in but not worker or event if that makes a...
0
1253
by: myprotein | last post by:
if "all applications disconnection" is anathor tigger of page cleaner? hi all I discovered that when all application disconnect from the database, db2 will "truncate" current active log file and push forward a new log file either by reusing a exist log or by generating a new log file. when anather application get connected to current database, execute "db2 get db cfg for xxxxx", u should see that the first active log is just the file...
3
2186
by: jlgeris | last post by:
I have a fairly simple client/server structure using System.Net.Sockets, where the server only sends data to a collection of clients, and the clients only receive data, so, the data flow is unidirectional. My server sends the same data to each of the connected clients, at the same time through a for loop. The loop sends the data, or removes the client if it has disconnected. My problem is when the client disconnects, it can cause the server...
2
1136
by: =?Utf-8?B?Um9nZXIgVHJhbmNoZXo=?= | last post by:
Hello, We have an application that use data from our sql server. We access this information trough TableAdapters, direct queries and datacontextS (LINQ). All these methods use the same CONNECTION STRING located on the application settings.
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9424
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.