发送方按照一定规则(周期性发送、空闲发送等等)向接收方发送固定格式的消息,接受方收到消息后回复一个固定格式的消息,如果长时间没有收到,比如心跳周期的3倍,则认为当前连接失效,将其断开。 注:发送方可以是客户端或者服务端,根据实际情况而定,常见是客户端作为发送方。
判断长连接是否存活:当长连接没有流量时,无法判断是通信异常引起还是通信正常没有业务流量引起,通过发送心跳包进行判断。