[zeromq-dev] Binding to TCP port 0

Pieter Hintjens ph at imatix.com
Wed Jan 25 16:07:05 CET 2012


On Wed, Jan 25, 2012 at 8:58 AM, Pierre Ynard <linkfanel at yahoo.fr> wrote:

> I want to bind a zeromq socket to an available TCP port assigned by the
> OS. However the standard way of doing this, binding to port 0, fails
> with EINVAL. Indeed, there is a check in the code saying that 0 is not a
> valid port. Is there any reason for this? Is there another way of doing
> this?

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

-Pieter



More information about the zeromq-dev mailing list