[zeromq-dev] ZMQ occupies random TCP ports on Windows

Martin Sustrik sustrik at 250bpm.com
Wed Sep 28 08:30:31 CEST 2011

Hi Michal,

> Unfortunately ZMQ opens arbitrary TCP ports on Windows in order to
> simulate socketpair(3) functionality [1] that is used by some kind of
> signalling mechanism(?). As a result sometimes application port gets
> occupied by another instance and my application fails to start.

Yes. This is a serious problem.

The background goes like this:

0MQ needs socket-based internal communication for sending events between 
application threads and I/O threads.

On POSIX platforms it uses socketpair() which in turn uses UNIX domain 
sokcets, ie. there are no TCP connections created in the background.

Unfortunately, on Windows there's no socketpair(). There are NamedPipes 
but these are *not* sockets, rather HANDLEs, which in turn means that 
they can't be polled on using select(). (We would need IOCP support to 
poll on NamedPipes.)

So, 0MQ creates a TCP connection between each socket and the I/O thread 
it uses for background processing.

The silly thing is that it uses new destination port for each of those 

Possible solution is to use a single fixed port for all these internal 


More information about the zeromq-dev mailing list