When a new connection is opened it will be passed to this method.
public handleConnect ( Kraken\Network\NetworkConnectionInterface $conn ) | ||
$conn | Kraken\Network\NetworkConnectionInterface |
/** * 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); } }
/** * @override * @inheritDoc */ public function handleConnect(NetworkConnectionInterface $conn) { if ($this->isAddressBlocked($conn->getHost())) { return $conn->close(); } return $this->component->handleConnect($conn); }
/** * @override * @inheritDoc */ public function handleConnect(NetworkConnectionInterface $conn) { if (!isset($conn->WebSocket) || ($id = $conn->WebSocket->request->getCookie(ini_get('session.name'))) === null) { $saveHandler = $this->nullHandler; $id = ''; } else { $saveHandler = $this->handler; } $conn->Session = new Session(new VirtualSessionStorage($saveHandler, $id, $this->serializer)); if (ini_get('session.auto_start')) { $conn->Session->start(); } return $this->component->handleConnect($conn); }
/** * @override * @inheritDoc */ public function handleMessage(NetworkConnectionInterface $conn, NetworkMessageInterface $message) { if ($conn->httpHeadersReceived !== true) { try { if (($request = $this->httpDriver->readRequest($conn->httpBuffer, $message->read())) === null) { return; } } catch (Error $ex) { return $this->close($conn, 413); } catch (Exception $ex) { return $this->close($conn, 413); } $conn->httpHeadersReceived = true; $conn->httpRequest = $request; $this->httpServer->handleConnect($conn); $this->httpServer->handleMessage($conn, $request); } else { $this->httpServer->handleMessage($conn, $message); } }
/** * @override * @inheritDoc */ protected function attemptUpgrade(NetworkConnectionInterface $conn) { $request = $conn->WebSocket->request; if (!$this->wsDriver->checkVersion($request)) { return $this->close($conn); } $conn->WebSocket->version = $this->wsDriver->getVersion($request); try { $response = $conn->WebSocket->version->wsHandshake($request); } catch (Error $ex) { return; } catch (Exception $ex) { return; } $conn->send($response); if ($response->getStatusCode() !== 101) { return $conn->close(); } $upgraded = $conn->WebSocket->version->wsUpgrade($conn, $this->wsServer); $this->connCollection->attach($conn, $upgraded); $upgraded->WebSocket->established = true; $this->wsServer->handleConnect($upgraded); }