The problem of socket, disconnection and reconnection

client and server communication, client network outage, power outage, why the server can not independently detect client disconnection (without heartbeat mechanism).

Jun.20,2021

normal disconnection client will send a fin packet to the server. The server will not know the connection is broken until it receives the fin packet.
when the network is cut off and the power is cut off, the client cannot send fin packets to the server, so the server cannot detect that the client is short-term.
in order to alleviate this problem, the server needs to have a heartbeat logic, that is, when the server detects how long a client has not sent any data, it thinks that the client has been disconnected.
this requires the client to send heartbeat data to the server regularly to maintain the connection


. However, it is not necessary to be so complicated in the implementation process. After linking to websocket, To maintain a link, you only need to initiate a heartbeat to the client every few seconds, and if you fail to send it three times in a row, you can disconnect it.
in implementation, it is best not to let the client send the heartbeat all the time, so that if the client does not write well, it is easy to have problems.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf6a59-32014.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf6a59-32014.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?