Subj : Re: Closing tcp socket connections To : comp.programming From : Alex Fraser Date : Mon Aug 15 2005 02:58 pm "Martin Hierholzer" wrote in message news:ddi105$lvc$1@sagnix.uni-muenster.de... > I have a problem closing tcp network server sockets. I have written a > (single threaded) server which is running on Linux (2.6.12-gentoo-r6) and > a client which should run on Linux and Windows. > The protocol between client and server is very simple, for every data > packet sent by the client a new connection will be opened, the client > will send its data and the server sends a reply and should close the > connection. This is very inefficient, it would be better to maintain connections. > For testing stability, I send these small packets as fast as I can, so > many packets arrive per second. > To close the connection, the server makes calls to shutdown and close on > the appropriate socket: [snip code] > But the connections seem to stay open even after these calls. Running > netstat even immediately after cancelling the test client shows a lot of > connections to my server, with state TIME_WAIT. The TIME_WAIT state exists to drain "stray" packets; it is perfectly normal. In particular, it does not indicate a problem with your code. Stare at a TCP state transition diagram until you understand it :). Alex .