
In windows there is the capability to create a socket with an address but leave the port number up to windows to select. Is this possible with the asio endpoint or will I always need to define "some" port number? Ryan

Ryan McConnehey wrote:
In windows there is the capability to create a socket with an address but leave the port number up to windows to select. Is this possible with the asio endpoint or will I always need to define "some" port number?
Something like this used to work (old version of asio): ---- (some using declarations omitted) asio::io_service ios; tcp::socket s(ios); tcp::socket::endpoint_type ep(tcp::v4(), 0); // NOTE: Usage of "0" s.open(tcp::v4()); s.set_option(tcp::socket::reuse_address(true)); s.bind(ep); --- s.local_endpoint().port() now holds actual port number bound to. HTH / Johan

Johan Nilsson wrote:
Ryan McConnehey wrote:
In windows there is the capability to create a socket with an address but leave the port number up to windows to select. Is this possible with the asio endpoint or will I always need to define "some" port number?
Something like this used to work (old version of asio):
---- (some using declarations omitted)
asio::io_service ios; tcp::socket s(ios); tcp::socket::endpoint_type ep(tcp::v4(), 0); // NOTE: Usage of "0"
s.open(tcp::v4());
s.set_option(tcp::socket::reuse_address(true)); s.bind(ep);
---
s.local_endpoint().port() now holds actual port number bound to.
HTH / Johan Thanks, I'll try that.
Ryan
participants (2)
-
Johan Nilsson
-
Ryan McConnehey