Strange Socket behaviour on Shutdown
-
Hi, I have tracked a strange behavior when I close a .NET TCP Socket. I wrote a TCP-Server which listens on port 6000. I now connect with an self written TCP-Client and everything works fine. When I want to disconnect the client from the server I call code like this:
public void Disconnect() { if (socket.Connected) socket.Shutdown(SocketShutdown.Both);:~ socket.Close(); socket = null; }
When I now run "netstat -a -p tcp" from the commadline I can still see the connection with the state: localhost:6000 -> localhost:6001 = CLOSING_WAIT (translated from german: SCHLIESSEN_WARTEN) localhost:6001 -> localhost:6000 = FIN_WAIT_2 (translated from german: FIN_WARTEN_2) Looks like there are some fragments of the connection still there. By the way... I am not able to create new connection on the same port at this time. Only when I finish my application, the connection between 6000:6001 in "netstat" is gone. The strange thing is, that if I disconnect with the code below, everything works fine. I cant find any connections with "netstat" after the disconnection, and I'm able to create a new connection with the same ports... :confused: Here is the code:public void Disconnect() { //Do NOT shutdown!!! //if (socket.Connected) // socket.Shutdown(SocketShutdown.Both); socket.Close(); socket = null; }
So... can someone tell me what is happening here? As far as I know it should be right and neccessary to callsocket.Shutdown(...)
with the TCP-Protocol. I read a lot of MSDN documentation but couldnt find any clues to this. As far as I tracked the problem, it only appears when I callsocket.Shutdown(Socketshutdown.Send)
.socket.Shutdown(Socketshutdown.Receive)
works apperntly fine. Maybe there is some socket coder outside that can help me.;) Thanks in advance, Snow.