Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] Howto bind *client* to a specific port?
From: for-gmane (for-gmane_at_[hidden])
Date: 2010-10-01 16:51:21


On 2010-10-01 17:03, for-gmane wrote:
> A NewbieQ:
>
> From a client app I want to connect to a server app on a remote host
> (say port 6666).
> A requirement is that the client shall be bound to a defined port (say
> port 5555).
> How to do this in asio?
> Does the client need to use an acceptor? (ok, this maybe sounds
> non-sensical, but who knows... :-)

Solved as follows:
     ...
     tcp::socket s(io_service);
     s.open(tcp::v4());
     s.set_option(tcp::socket::reuse_address(true));
     s.bind(tcp::endpoint(tcp::v4(), uLocalPortToUse));
     s.connect(*iterator);
     ...


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