
6 Mar
2006
6 Mar
'06
1:26 p.m.
Caleb Epstein wrote:
On 3/4/06, Jeff Flinn <TriumphSprint2000@hotmail.com> wrote:
I'm moving an MFC net app to asio. In that app CAsyncSocket/CSocket are
created using port=0, which MFC docs states: 'Windows Sockets to select a port'. Is there a similar facility in asio? If not any suggestions on a portable technique to get an available port?
The default constructor for ipv4::tcp::endpoint initializes the port to 0. Just pass a default-constructed endpoint to your socket_acceptor's ctor or to its bind method.
You can then use the get_local_endpoint method to get the value of the port that was allocated by the OS.
Thanks again Caleb. Jeff Flinn