[zeromq-dev] SO_REUSEADDR behavior on Windows

Pieter Hintjens ph at imatix.com
Tue Jun 29 20:43:24 CEST 2010

Yes, you're right. This is an old difference between the Windows and Linux
TCP stacks. I'll make that change. Thanks!


Sent from my Android mobile phone.

On Jun 29, 2010 6:29 PM, "Chris Trimble" <trimbo at gmail.com> wrote:

Try this pyzmq script on Windows and Linux:

>>> import zmq
>>> c = zmq.Context()
>>> s1 = c.socket(zmq.PUB)
>>> s1.bind("tcp://*:47000")
>>> s2 = c.socket(zmq.PUB)
>>> s2.bind("tcp://*:47000")

On linux, you'll get an error that the address is already in use.  On
Windows, there's no error.

Looks like this is because SO_REUSEADDR has a different behavior on Windows,
and is still being set as a sockopt.  MS says this:

"In the case where the first call to
> either SO_REUSEADDR or no socket options at all, the second bind call will
> "hijack" the port and the application will be unable to determine which of
> the two sockets received specific packets sent to the "shared" port."


Is this the intended behavior of ZMQ?  I'm not sure it will be determinate.

Looks like all that needs to be done to line up the behavior on windows is
change the sockopt to SO_EXCLUSIVEADDRUSE on line 67 of tcp_listener.cpp,
which is inside the windows #ifdef

 - Chris

zeromq-dev mailing list
zeromq-dev at lists.zeromq.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100629/3bf38726/attachment.htm>

More information about the zeromq-dev mailing list