Boost logo

Boost Users :

Subject: Re: [Boost-users] [Asio] Any port with an endpoint
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2009-10-22 11:47:05


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net