[zeromq-dev] Binding to TCP port 0

Martin Lucina martin at lucina.net
Thu Jan 26 01:19:55 CET 2012

Hi Pierre!

On Wed, 25 Jan 2012 18:22:55 +0100
Pierre Ynard <linkfanel at yahoo.fr> wrote:

> > If you're using the high level C binding this works. It's not a core
> > libzmq functionality. Some other bindings may also provide it.
> > 
> > You can check the CZMQ code that does this:
> > https://github.com/zeromq/czmq/blob/master/src/zsocket.c
> Thanks, but I don't really want to write an ugly for loop to (badly)
> reinvent a feature of the socket API. Also this code ignores the OS
> settings for local port assignation.

+1, I have proposed this functionality before, but we could not figure
out a way to make the API work. Its obvious that many people need
this, and have implemented it with the same hack as czmq.
> Why is it disabled in libzmq?

It is disabled because in ZeroMQ, by design, there is no way to work
with individual underlying connections of a socket. Hence, there is no
API equivalent to e.g. getsockname() which you could use to get the port
back from the OS.

If you can think of a way to make this work, without exposing the
details of the individual connections to the application, and
without a backward-incompatible API change, please propose it (or
even better, make a patch).

Martin Lucina <martin at lucina.net>

More information about the zeromq-dev mailing list