/** * {@inheritdoc} */ function onOpen(ConnectionInterface $conn) { if ($this->isBlocked($conn->remoteAddress)) { return $conn->close(); } return $this->_decorating->onOpen($conn); }
public function handleConnect($conn) { $conn->decor = new IoConnection($conn, $this); $conn->decor->resourceId = (int) $conn->stream; $conn->decor->remoteAddress = $conn->getRemoteAddress(); $this->app->onOpen($conn->decor); $conn->on('data', $this->handlers['data']); $conn->on('end', $this->handlers['end']); $conn->on('error', $this->handlers['error']); }
/** * {@inheritdoc} */ function onOpen(ConnectionInterface $conn) { if (null === ($id = $conn->WebSocket->request->getCookie(ini_get('session.name')))) { $saveHandler = $this->_null; $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->_app->onOpen($conn); }
/** * {@inheritdoc} */ public function onMessage(ConnectionInterface $from, $msg) { if (true !== $from->WebSocket->established) { try { if (null === ($request = $this->reqParser->onMessage($from, $msg))) { return; } } catch (\OverflowException $oe) { return $this->close($from, 413); } if (!$this->versioner->isVersionEnabled($request)) { return $this->close($from); } $from->WebSocket->request = $request; $from->WebSocket->version = $this->versioner->getVersion($request); $response = $from->WebSocket->version->handshake($request); $response->setHeader('X-Powered-By', \Ratchet\VERSION); // This needs to be refactored later on, incorporated with routing if ('' !== ($agreedSubProtocols = $this->getSubProtocolString($request->getTokenizedHeader('Sec-WebSocket-Protocol', ',')))) { $response->setHeader('Sec-WebSocket-Protocol', $agreedSubProtocols); } $from->send((string) $response); if (101 != $response->getStatusCode()) { return $from->close(); } $upgraded = $from->WebSocket->version->upgradeConnection($from, $this->_decorating); $this->connections->attach($from, $upgraded); $upgraded->WebSocket->established = true; return $this->_decorating->onOpen($upgraded); } $from->WebSocket->version->onMessage($this->connections[$from], $msg); }