How to close socket properly?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Rizzo

    #1

    How to close socket properly?

    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.
  • Peter Duniho

    #2
    Re: How to close socket properly?

    On Fri, 14 Dec 2007 11:01:33 -0800, Frank Rizzo <none@none.netw rote:
    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...search ing using the Winsock constant SO_REUSEADDR may turn up
    better details than looking at the .NET-specific docs).

    Pete

    Comment

    Working...