[zeromq-dev] automatically choosing a free TCP port

Brian Granger ellisonbg at gmail.com
Mon Mar 15 15:31:17 CET 2010


Using avahi with 0MQ would be quite nice.  The Python bindings have
the ability to bind to a random port in a range:


I would love to have Avahi integration in the Python bindings and have
worked with zeroconf a little bit before.  Let me know if you want to
pursue this.



On Mon, Mar 15, 2010 at 4:46 AM, David Robinson <zxvdr.au at gmail.com> wrote:
> Hi all,
> I'm looking at using avahi (eg, zeroconf) with a zeromq based
> application. I'd like to be able to have zeromq bind to any free port
> so that I can announce the service via avahi, but afaict the string
> passed to zmq_bind must have a port number. Is there any way to avoid
> specifying a TCP port number and just have one automatically assigned?
> Apparently you can "just create the socket and call listen() on it.
> Then, the IP stack will automatically assign a free port number. Use
> getsockname() to query the port number that has been chosen and use
> that when registering the Avahi service."  I tried using an address
> string of "tcp://lo" without success (eg, zmq_bind (socket,
> "tcp://lo")).
> There is an example at the link below that shows how this is done with
> normal sockets:
> http://git.0pointer.de/?p=avahi.git;a=blob;f=docs/socket-auto-port.c;h=75dffafe75f35c0aa2143e62f16ba8aa1c2804de;hb=HEAD
> -Dave
> _______________________________________________
> 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