How to close socket properly?

F

Frank Rizzo

When you close a socket (.e.g. .Shutdown, .Dispose, etc...), the socket
goes into TIME_WAIT mode for about 4 minutes, then gets killed by the
OS. However, during this time, the socket is not available. Is there a
way to close a socket, so that it actually closes and is immediately
available to be used by another application (or the same application)?

Thanks.
 
P

Peter Duniho

When you close a socket (.e.g. .Shutdown, .Dispose, etc...), the socket
goes into TIME_WAIT mode for about 4 minutes, then gets killed by the
OS. However, during this time, the socket is not available. Is there a
way to close a socket, so that it actually closes and is immediately
available to be used by another application (or the same application)?

The behavior you're seeing is intentional and not changeable at the
application level. You can use the ReuseAddress socket option as a
workaround but keep in mind that doing so may introduce ambiguities with
respect to which socket is actually going to receive data (I don't recall
the specifics off the top of my head...you'll want to read up on the
option...searching using the Winsock constant SO_REUSEADDR may turn up
better details than looking at the .NET-specific docs).

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top