diff --git a/src/Client.php b/src/Client.php index aad0685..1b42ced 100644 --- a/src/Client.php +++ b/src/Client.php @@ -82,6 +82,7 @@ public function __construct($uri, LoopInterface $loop, Resolver $resolver = null $this->loop = $loop; $this->resolver = $resolver; $this->state = self::STATE_CLOSED; + $this->heartbeat_interval = null; } public function connect() { diff --git a/src/Protocol/AbstractProtocol.php b/src/Protocol/AbstractProtocol.php index 0a05385..dd08cf2 100644 --- a/src/Protocol/AbstractProtocol.php +++ b/src/Protocol/AbstractProtocol.php @@ -60,7 +60,7 @@ public function onHeartbeat(){ } $this->client->getLoop()->addTimer($this->client->getHeartbeatInterval(), function(){ - //Set a new timeout (1 sec seems reasonable) + //Set a new timeout (2 sec seems reasonable) $this->heartbeat_timer = $this->client->getLoop()->addTimer(2, function(){ $this->stream->close(); throw new ConnectionLostException(); diff --git a/src/Protocol/RFC6455.php b/src/Protocol/RFC6455.php index 82e72c8..28766ba 100644 --- a/src/Protocol/RFC6455.php +++ b/src/Protocol/RFC6455.php @@ -141,7 +141,11 @@ private function processUpgrade(Response $response) { } $this->client->setState(Client::STATE_CONNECTED); - $this->sendHeartbeat(); + + if($this->client->getHeartbeatInterval() !== null){ + //Start the heartbeat loop + $this->onHeartbeat(); + } }