As the title suggest, I've worked with both winsock & boost sockets. I'm having an incredible difficulty detecting for disconnections.
First, I know that a disconnection can be discovered by the following:
- recv() / async_read() return a socket error or 0.
- send() / async_write() ... ... ...
- Whether the client closed manually, got interrupted / program closed - whatever.
So here's the problem scenarios:
I close my connection with closesocket(). The client detects the disconnect - all fine.
I close the program - there's a 50/50 chance the client fails to detect the disconnection. For some reason my overlapped IO WSARecv() isn't a guarantee detect.
I kill the process. The chances increase to 80% of detection. But for the rest of the 20% - here's what's bothering me. I implemented a keep-alive ping mechanism which sends data to the server. Even if I killed the program - the server is still async_writing() to the connection - even though it's not detected or dead.
Is this something I have to live with? I'm kind of lost since I tried everything in my power to detect disconnections... yet they're still a problem.