Esempio n. 1
0
 public function onTick(ServerClient $client)
 {
     $time = (int) $client->getAttribute('tick');
     if ($time == time()) {
         return;
     }
     $client->setAttribute('tick', time());
     $this->output->writeln(sprintf('<info>Client[%s:%d]</info> :: <comment>%s</comment>', $client->getHost(), $client->getPort(), __METHOD__));
 }
Esempio n. 2
0
 public function onTick(ServerClient $client)
 {
     static $time;
     $time = isset($time) ? $time : 0;
     if ($time == time()) {
         return;
     }
     $time = time();
     $this->output->writeln(sprintf('<info>Client[%s:%d]</info> :: <comment>%s</comment>', $client->getHost(), $client->getPort(), __METHOD__));
 }
Esempio n. 3
0
 /**
  * @param ServerClient $client
  * @return void
  */
 public function onWebSocketDisconnect(ServerClient $client)
 {
     $this->output->writeln(sprintf('<info>%s</info> :: <comment>%s</comment>', $client->getId(), __METHOD__));
 }
Esempio n. 4
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;
 }