473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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_Click(object sender, System.EventArgs e)
{
if (serverSock != null)
{
if (serverSock.Connected)
{
Send(serverSock, "quit\r\n");
sendDone.WaitOne();
serverSock.Shutdown(SocketShutdown.Both);
serverSock.Close();
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 1716
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**********@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.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_Click(object sender, System.EventArgs e)
{
if (serverSock != null)
{
if (serverSock.Connected)
{
Send(serverSock, "quit\r\n");
sendDone.WaitOne();
serverSock.Shutdown(SocketShutdown.Both);
serverSock.Close();
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
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...
5
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...
2
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...
9
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,...
4
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...
2
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...
0
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...
3
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.