24 Jul
2009
24 Jul
'09
10:03 a.m.
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