Socket Disconnect

  • Thread starter Thread starter xincmu
  • Start date Start date
X

xincmu

I built a very basic server-client in C#. When my server disconnects
from the client, the socket at the server is already disconnected, but
the socket the client remains open. I used the sample code in .Net's
documentation to disconnect:

socket.Shutdown( SocketShutdown.Both );
socket.Disconnect( false );

I also tried

socket.Close() instead of Disconnect.

I compiled my code with MS Studio 2005. When I used to compile it
with MS Studio 2003, it worked just fine.

Anybody had the same problem? Thanks.
 
I built a very basic server-client in C#. When my server disconnects
from the client, the socket at the server is already disconnected, but
the socket the client remains open. I used the sample code in .Net's
documentation to disconnect:

socket.Shutdown( SocketShutdown.Both );
socket.Disconnect( false );

I also tried

socket.Close() instead of Disconnect.

I compiled my code with MS Studio 2005. When I used to compile it
with MS Studio 2003, it worked just fine.

Anybody had the same problem? Thanks.

Is the client connecting through a switch or a router? I believe they
can hold onto a connection for a period of time. At least that is
what I suspect from problems I have in trying to work out
connection/disconnection issues.
 
Is the client connecting through a switch or a router? I believe they
can hold onto a connection for a period of time. At least that is
what I suspect from problems I have in trying to work out
connection/disconnection issues.

Both the client and server are on the same machine. It is for testing
purpose.
The thing which confuses most is that after the server has
disconnected, the client still tries to call the socket.Send function,
it went through without any error.
 
Both the client and server are on the same machine. It is for testing
purpose.
The thing which confuses most is that after the server has
disconnected, the client still tries to call the socket.Send function,
it went through without any error.

I found the problem. Disconnect fails when there's no traffic between
the server and the client.
Make sure you send a 1 byte message when you want to test for
connection. Calling Send with 0 byte messages won't work.
 
Back
Top