Let someone send a message to my socket, he accepts it with the function receive_from(asio::buffer(buffer, size), SenderEndPoint) , where SenderEndPoint from boost::asio::ip::udp::endpoint . Then, I reply via send_to(asio::buffer(buffer2), SenderEndPoint) for the same SenderEndPoint .

But there is one problem: if the one who initially sent the message closed the socket, the program crashes with an exception. I tried to surround the try-catch sending with exceptions from both std::exception and boost::exception , but for some reason this exception is caught by a much higher top try-catch from the main (this whole thing I described above occurs in the class object ).

Is it possible to somehow make a check on the availability of the socket from the sender, if boost::asio::ip::udp::socket for receiving and sending on my side?

    1 answer 1

    The arrival of an exception in main is quite logical - this is asynchronous execution. Catch him there and react as you need.

    • This, of course, may be the solution, but the question still was: can SenderEndPoint be checked for accessibility? - Dmitry
    • 3
      the only normal way to check that there is a connection and you can write to it is to try to write there. All other methods either come down to this or do not work :) - KoVadim