[zeromq-dev] SO_REUSEADDR behavior on Windows

Brian Granger ellisonbg at gmail.com
Tue Jun 29 21:33:10 CEST 2010


Pieter,

Thanks!

Brian

On Tue, Jun 29, 2010 at 1:43 PM, Pieter Hintjens <ph at imatix.com> wrote:
> Yes, you're right. This is an old difference between the Windows and Linux
> TCP stacks. I'll make that change. Thanks!
>
> -Pieter
>
> 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 bind sets 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."
>
> http://msdn.microsoft.com/en-us/library/ms740621(VS.85).aspx
> 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
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>



-- 
Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo
bgranger at calpoly.edu
ellisonbg at gmail.com



More information about the zeromq-dev mailing list