By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,019 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

Socket Disconnect

P: n/a
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.

Mar 3 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 3 Mar 2007 14:58:32 -0800, xi****@yahoo.com wrote:
>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.
Mar 3 '07 #2

P: n/a
On Mar 3, 3:25 pm, r norman <r_s_norman@_comcast.netwrote:
On 3 Mar 2007 14:58:32 -0800, xin...@yahoo.com wrote:
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.
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.
Mar 3 '07 #3

P: n/a
On Mar 3, 3:32 pm, xin...@yahoo.com wrote:
On Mar 3, 3:25 pm, r norman <r_s_norman@_comcast.netwrote:
On 3 Mar 2007 14:58:32 -0800, xin...@yahoo.com wrote:
>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.

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.
Mar 4 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.