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(); }
/** * 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); }