
22 Oct
2009
22 Oct
'09
3:47 p.m.
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