How to know the connected server is down ?
Hi, I am using the boost socket for the client and server connection. i set the socket option as below boost::asio::socket_base::keep_alive option(true); tcp_socket->set_option(option); I am able to connect the client to the server. Suppose after some time the server goes down. How do I get that information without sending any read/write request? 1. Now I don't know how to check if the client is down ? 2. Do I get the signal that the client is down? (Without reading or writing at the client )? . If yes, how to handle it. Please help me with this ... -- Regards Raghavendra Huchchannavar.
On 9/8/22 00:25, Richard Hodges via Boost wrote:
How do I get that information without sending any read/write request?
You don't. This is like being blind and asking, "how do I know that the person is still there if I don't listen or reach out to touch him?"
Keep-alive *is* that implicit sending request, that's the whole point of it. I didn't test this but my understanding is that when the connection is closed according to TCP keep-alive settings then: 1. If you're using the connection socket with select/poll/epoll/etc. then the socket becomes signalled with error (as if closed). 2. Otherwise, if you're not blocking signals, SIGPIPE is delivered. 3. Otherwise, you will find that the connection is closed the next time you try to send. So, unless you have detected the connection is closed by one of the above methods, you can assume it is *probably* alive. I say "probably" because it may not be actually alive - only that the keep-alive mechanism has not yet detected its termination. Keep-alive settings are very (too) liberal on most systems, to the point that the mechanism is not practical in most cases when you actually need it to detect connection loss. Which is why often applications don't bother with it and implement their own pinging protocols.
participants (3)
-
Andrey Semashev
-
Raghu Huchchannavar
-
Richard Hodges