Esempio n. 1
0
 /**
  * Handler triggered when a new connection is received from SocketListener.
  *
  * @param SocketListenerInterface $server
  * @param SocketInterface $socket
  */
 public function handleConnect($server, $socket)
 {
     $socket->conn = new SocketConnection($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);
     }
 }
Esempio n. 2
0
 /**
  * @override
  * @inheritDoc
  */
 public function handleConnect(IoConnectionInterface $conn)
 {
     if (!isset($conn->WebSocket) || null === ($id = $conn->WebSocket->request->getCookie(ini_get('session.name')))) {
         $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);
 }
Esempio n. 3
0
 /**
  * @override
  * @inheritDoc
  */
 public function handleConnect(IoConnectionInterface $conn)
 {
     if ($this->isBlocked($conn->getHost())) {
         return $conn->close();
     }
     return $this->component->handleConnect($conn);
 }
Esempio n. 4
0
 /**
  * @param IoConnectionInterface $conn
  */
 protected function attemptUpgrade(IoConnectionInterface $conn)
 {
     $request = $conn->WebSocket->request;
     if (!$this->wsDriver->isVersionEnabled($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;
     }
     //        $agreedSubProtocols = $this->getSubProtocolString($request->getHeader('Sec-WebSocket-Protocol'));
     //
     //        if ($agreedSubProtocols !== '')
     //        {
     //            $response->setHeader('Sec-WebSocket-Protocol', $agreedSubProtocols);
     //        }
     $conn->send((string) $response);
     if ($response->getStatusCode() !== 101) {
         return $conn->close();
     }
     $upgraded = $conn->WebSocket->version->wsUpgrade($conn, $this->wsServer);
     $this->connectionCollection->attach($conn, $upgraded);
     $upgraded->WebSocket->established = true;
     $this->wsServer->handleConnect($upgraded);
 }
Esempio n. 5
0
 /**
  * @override
  */
 public function handleMessage(IoConnectionInterface $conn, IoMessageInterface $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);
     }
 }