This really depends on your choice of protocol.
Simple Command Protocol
If your server protocol always waits for a message from the client, you will always have a pending async_read
for every client connected. This should return with an error (EOF) when a client disconnects in any fashion.
Keep-alive is an approach as said above, but pending async_read
's work just fine for this purpose.
Simple Event Protocol
A simple event protocol involves a client listening for data and the server sending it. In this protocol, the server has no idea whether the client is there, because the client merely accepts the data and continues waiting. The client never sends the server any message whatsoever.
This presents the requirement for keep-alive. async_write
operations do not fail in the same way that async_read
's do when a client is already disconnected.
There are other options, like having the server always have a pending async_read
operation that tries to read 1 byte. This will fail when the client disconnects similar to the Simple Command Protocol discussion above, but will never succeed either because the client doesn't send data over the Simple Event Protocol.