When binding a client TCP socket to a specific local port with Winsock, SO_REUSEADDR does not have a

Posted by Checkers on Stack Overflow See other posts from Stack Overflow or by Checkers
Published on 2010-04-09T05:02:52Z Indexed on 2010/04/09 5:13 UTC
Read the original article Hit count: 344

Filed under:
|
|
|
|

I'm binding a client TCP socket to a specific local port. To handle the situation where the socket remains in TIME_WAIT state for some time, I use setsockopt() with SO_REUSEADDR on a socket.

It works on Linux, but does not work on Windows, I get WSAEADDRINUSE on connect() call when the previous connection is still in TIME_WAIT.

MSDN is not exactly clear what should happen with client sockets:

[...] For server applications that need to bind multiple sockets to the same port number, consider using setsockopt (SO_REUSEADDR). Client applications usually need not call bind at all—connect chooses an unused port automatically. [...]

How do I avoid this?

© Stack Overflow or respective owner

Related posts about winsock

Related posts about winapi