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

后端 未结 6 1779
难免孤独
难免孤独 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条回答
  •  -上瘾入骨i
    2020-12-11 04:50

    I think that in general once you open a socket, you should start reading it inmediately and never stop doing so. This way you can make your server or client to support both synchronous and asynchronous protocols. The moment the client closes the connection, the moment the read will tell you this.

提交回复
热议问题