[Asio] How can you detect port collsions?

Hi All Thanks to those of you who have answered my previous asio queries - I'm gradually gaining on the problems! I am allocating port numbers on tcp connections dynamically, and must allocate and reserve the port number without blocking. I also have multiple instances of the process which needs to do this, and I'm plagued by port collisions. How do I detect, and avoid, port number collsions? Thanks, Rob.

I am allocating port numbers on tcp connections dynamically, and must allocate and reserve the port number without blocking. I also have multiple instances of the process which needs to do this, and I'm plagued by port collisions.
How do I detect, and avoid, port number collsions?
This is not ASIO, specific but hopefully it is possible using ASIO: 1) bind() socket to port 0. The IP stack should now assign a free port to the socket. 2) obtain the assigned port number using getsockname(). 3) listen() / profit. :-) Best regards, Martin Dyring-Andersen
participants (2)
-
Martin Dyring-Andersen
-
Robert Jones