|
...
|
...
|
@@ -159,8 +159,14 @@ class Websocket |
|
|
|
$this->pingState = false;
|
|
|
|
$this->timerCheck = swoole_timer_after(5000, function () {
|
|
|
|
if (!$this->pingState) {
|
|
|
|
output($this->desc, 'ping pong 超时,重新连接');
|
|
|
|
$this->connect($this->onOpen, $this->onMessage, $this->onClose, $this->onPing, $this->onPong);
|
|
|
|
//未收到pong且10内未获取数据。假定已断开连接(存在未收到pong,但在传数据的情况。)
|
|
|
|
if($this->lastRecvTime<time()-10){
|
|
|
|
output($this->desc, 'ping pong 超时且未收到数据,重新连接');
|
|
|
|
$this->connect($this->onOpen, $this->onMessage, $this->onClose, $this->onPing, $this->onPong);
|
|
|
|
}else{
|
|
|
|
output($this->desc, 'ping pong 超时,再次ping');
|
|
|
|
$this->sendPing();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
...
|
...
|
@@ -174,7 +180,10 @@ class Websocket |
|
|
|
}
|
|
|
|
swoole_timer_clear($this->timerCheck);
|
|
|
|
$this->timerPing = swoole_timer_after($this->pingDelay, function () {
|
|
|
|
$this->sendPing();
|
|
|
|
//防止重复ping
|
|
|
|
if($this->pingState){
|
|
|
|
$this->sendPing();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} |
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|