How to check if socket is closed in Boost.Asio?

后端 未结 6 1783
难免孤独
难免孤独 2020-12-11 04:17

What is the easiest way to check if a socket was closed on the remote side of the connection? socket::is_open() returns true even if it is closed on the remote

6条回答
  •  时光取名叫无心
    2020-12-11 04:55

    Using error_code is able to check the condition whether the client is connected or not. If the connection is success, the error_code error.value() will return 0, else return other value. You can also check the message() from the error_code.

提交回复
热议问题