/** * Handler triggered when a new connection is received from SocketListener. * * @param SocketListenerInterface $server * @param SocketInterface $socket */ public function handleConnect($server, $socket) { $socket->conn = new NetworkConnection($socket); try { $this->component->handleConnect($socket->conn); $socket->on('data', [$this, 'handleData']); $socket->on('error', [$this, 'handleError']); $socket->on('close', [$this, 'handleDisconnect']); } catch (Error $ex) { $this->close($socket); } catch (Exception $ex) { $this->close($socket); } }
/** * @param string $event * @param callable $callback */ protected function setEventListener($event, callable $callback) { if ($this->socket !== null) { $this->socket->on($event, $callback); } }