Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::Asio async_accept not throwing exception
From: Rutger ter Borg (rutger_at_[hidden])
Date: 2010-11-22 04:19:33


On 11/21/2010 12:12 PM, Lloyd Kanakkassery wrote:
>
> Another program is already listening on the port "13" (A service version
> of the same program). When this new program tries to listen
> (async_accept) on port "13", no exception is thrown!.
>
> How can I check weather the port is already open?
>
> Thanks,
> Lloyd

Do not call async_accept directly, rather do something like

try {
   acceptor_.open( (endpoint.protocol)() );
   acceptor_.set_option( boost::asio::ip::tcp::acceptor::reuse_address(
true ) );
   acceptor_.bind( endpoint );
   acceptor_.listen();
} ...
acceptor_.async_accept( ... );

If the port is already open, it will throw.

HtH,
Cheers,

Rutger


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