Beispiel #1
0
 public function onConnection(Connection $connection)
 {
     $iterator = $connection->read()->getIterator();
     while ((yield $iterator->isValid())) {
         $message = $iterator->getCurrent();
         print "message: {$message}\n";
         (yield $connection->send(new Message($message)));
     }
     $connection->close();
 }
Beispiel #2
0
 /**
  * Generate a client hash like a client ID
  *
  * @return     string  The client hash
  */
 protected function generateClientHash() : string
 {
     return md5($this->connection->getRemoteAddress() . $this->connection->getRemotePort());
 }
 /**
  * Create a client array of a Connection and a User object and handle the client session with until the connection
  * is closed
  *
  * @coroutine
  *
  * @param      \Icicle\WebSocket\Connection   $connection
  *
  * @return     \Generator|\Icicle\Awaitable\Awaitable|null
  */
 private function connectionSessionHandle(Connection $connection)
 {
     $client = new Client($connection);
     $iterator = $connection->read()->getIterator();
     $this->clients->add($client);
     (yield $connection->send(json_encode(['service' => 'clientService', 'action' => 'connect', 'id' => $client->getId(), 'connection' => ['remoteAddress' => $connection->getRemoteAddress(), 'remotePort' => $connection->getRemotePort()]])));
     while ((yield $iterator->isValid())) {
         (yield $this->serviceSelector(json_decode($iterator->getCurrent()->getData(), true), $client));
         $this->logger->log(LogLevel::DEBUG, $this->rooms[0]);
     }
     $this->onDisconnection($client);
 }