Ejemplo n.º 1
0
 /**
  * @param ServerClient $client
  * @return void
  */
 public function onWebSocketDisconnect(ServerClient $client)
 {
     $this->output->writeln(sprintf('<info>%s</info> :: <comment>%s</comment>', $client->getId(), __METHOD__));
 }
Ejemplo n.º 2
0
 /**
  * @param ServerClient $client
  * @return self
  */
 public function sendWebSocketPing(ServerClient $client) : self
 {
     $hash = hash('sha256', sprintf('%s_%s_%s', $client->getId(), uniqid('', true), microtime(true)));
     $code = sprintf('%s:%s', $hash, microtime(true));
     $client->setAttribute('_websocket_ping_code', $code);
     $client->setAttribute('_websocket_ping_time', time());
     $frame = new Frame(['opcode' => FRAME::TYPE_PING, 'body' => $code, 'length' => strlen($code), 'mask' => (bool) $client->getAttribute('_websocket_mask')]);
     $this->send($client, $frame->encode());
     return $this;
 }