keep connected - noradle/noradle-dispatcher GitHub Wiki

keep-alive 机制

  • 发送 ping/pong 管理包

  • 发出 ping 后,一直没有 pong 包响应,就认为对端死掉,相当于 socket error/end 事件

  • At handshake, client send keep-alive-interval to noradle-dispatcher

  • noradle-dispatcher call socket.setTimeout(num, cb) to monitor timeout event

  • when timeout detected, set state to probe, and send a ping frame, and wait for 3s with another setTimeout

  • if no pong is received, treat the connection as dead, call socket.end, release resources

  • if pong is received within time limit, it's ok

graceful quit 机制

发送 quit 管理包,通知对端不要再发送新包,当前请求的还允许继续

连接中断事件检测

发现异常中断事件,需要看是否有在途请求,并作响应处理