In general, only send or recv is required, and if the result is zero, the line is dropped. 1. When the recv return value of 0 is a disconnect that indicates that the other party is already normal (MSDN said to be perfect).
2. When Recv returns to Socket_error, it indicates that the other party is disconnected, but may be disconnected (off-screen or end-of-client process). If you are worried about being blocked while reading, use Select (This is not a good idea) but, under a long connection, It is possible that there is no data exchange for a long time. At this point the heartbeat mechanism is needed, and TCP itself has a heartbeat mechanism. If you set a heartbeat, TCP will send your heartbeat (say 2 times) within a certain amount of time (for example, 3 seconds), and this information will not affect your own defined protocol. The so-called "Heartbeat" is the time to send a custom structure (heartbeat packet or heartbeat frame), let the other side know that they are "online." To ensure the validity of the link. The so-called heartbeat packet is the client sends a simple message to the server and tells it I'm still there. In general, the heartbeat packet is mainly used for long-connection keepalive and disconnection processing. In general application, the judgment time in 30-40 seconds is quite good. If the demand is high, it will be 6-9 seconds.
Server determines if HTTP is interrupted