You are not logged in.

#1 2011-10-28 17:53:09

rubdos
Member
Registered: 2011-09-22
Posts: 61

c++ boost::asio test if host is online

Hi guys!

When I try to (synch) connect to a TCP port on an IP that's NOT online, the program stops running at the .connect(); point. How can I check on beforehand if the host is online?
I'm using TCP sockets in boost c++.

Should I ping?

Ruben

Offline

#2 2011-10-29 07:14:46

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: c++ boost::asio test if host is online

You can't check beforehand whether a host is available or not, especially not with pings.  The host might still become unavailable between the check and the actual connection attempt, and it might well respond to pings, but still not provide the specific port you are trying to connect to.  You can also connect to hosts, which aren't pingable.

If a host is not available, "connect()" will wait until a time-out occurs.  I don't know the boost API well enough to tell you whether you can configure this time-out, but if not, you can still use the asynchronous methods (e.g. "async_connect()").  After all, that is what boost::asio is actually made for.

Offline

Board footer

Powered by FluxBB