/**
  * Limits the given connection
  *
  * @param Connection $connection
  * @param string $limit Reason
  */
 protected function limit($connection, $limit)
 {
     $this->logger->info(sprintf('Limiting connection %s: %s', $connection->getIp(), $limit));
     $connection->close(new RateLimiterException($limit));
 }
 /**
  * Handle a complete payload received from the client
  *
  * Public because called from our PayloadHandler
  *
  * @param string $payload
  */
 public function handlePayload(Payload $payload)
 {
     $app = $this->getClientApplication();
     $this->logger->debug('Handling payload: ' . $payload->getPayload());
     switch ($type = $payload->getType()) {
         case Protocol::TYPE_TEXT:
             if (method_exists($app, 'onData')) {
                 $app->onData($payload, $this);
             }
             return;
         case Protocol::TYPE_BINARY:
             if (method_exists($app, 'onBinaryData')) {
                 $app->onBinaryData($payload, $this);
             } else {
                 $this->close(1003);
             }
             break;
         case Protocol::TYPE_PING:
             $this->logger->info('Ping received');
             $this->send($payload->getPayload(), Protocol::TYPE_PONG);
             $this->logger->debug('Pong!');
             break;
             /**
              * A Pong frame MAY be sent unsolicited.  This serves as a
              * unidirectional heartbeat.  A response to an unsolicited Pong
              * frame is not expected.
              */
         /**
          * A Pong frame MAY be sent unsolicited.  This serves as a
          * unidirectional heartbeat.  A response to an unsolicited Pong
          * frame is not expected.
          */
         case Protocol::TYPE_PONG:
             $this->logger->info('Received unsolicited pong');
             break;
         case Protocol::TYPE_CLOSE:
             $this->logger->info('Close frame received');
             $this->close();
             $this->logger->info('Disconnected');
             break;
         default:
             throw new ConnectionException('Unhandled payload type');
     }
 }
Exemple #3
0
 /**
  * Constructor
  *
  * @param string $uri Websocket URI, e.g. ws://localhost:8000/, path will
  *                     be ignored
  * @param array $options (optional) See configure
  */
 public function __construct($uri, array $options = array())
 {
     $this->uri = $uri;
     parent::__construct($options);
     $this->logger->info('Server initialized');
 }