[zeromq-dev] How to limit the range for zmq_bind() in C++?
Brett Viren
brett.viren at gmail.com
Thu May 14 18:29:49 CEST 2020
Hi Mike,
"Alexander, Michael" <Michael.Alexander at xerox.com> writes:
> I have been using zmq_bind(socket, “tcp://lo:*”) to bind to a random
> unused port. I can find examples using other languages to use
> random_port to limit the range of ports (e.g. only assign a port
> between 30000 and 31000). Is there a way to do this in C++?
Maybe it's heavy handed, but I do this by manually looping over a port
range, continuing until I no longer get an error from cppzmq's
zmq::socket_t::bind():
https://github.com/brettviren/zio/blob/master/src/port.cpp#L44
Actually, now I check cppzmq and I'm not sure why I did this because I
see cppzmq simply passes through the address to zmq_bind(). So, if
"tcp://lo:*" works with libzmq, I think it should work with cppzmq.
-Brett.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20200514/284b0e2e/attachment.sig>
More information about the zeromq-dev
mailing list