Example #1
0
 /**
  * @see Wrench\Listener.Listener::listen()
  */
 public function listen(Server $server)
 {
     $this->server = $server;
     $server->addListener(Server::EVENT_SOCKET_CONNECT, array($this, 'onSocketConnect'));
     $server->addListener(Server::EVENT_SOCKET_DISCONNECT, array($this, 'onSocketDisconnect'));
     $server->addListener(Server::EVENT_CLIENT_DATA, array($this, 'onClientData'));
 }
 /**
  * Removes a connection
  *
  * @param Connection $connection
  */
 public function removeConnection(Connection $connection)
 {
     $socket = $connection->getSocket();
     if ($socket->getResource()) {
         $index = $socket->getResourceId();
     } else {
         $index = array_search($connection, $this->connections);
     }
     if (!$index) {
         $this->log('Could not remove connection: not found', 'warning');
     }
     unset($this->connections[$index]);
     unset($this->resources[$index]);
     $this->server->notify(Server::EVENT_SOCKET_DISCONNECT, array($connection->getSocket(), $connection));
 }
Example #3
0
 /**
  * @see Wrench.Server::configure()
  */
 protected function configure(array $options)
 {
     $options = array_merge(array('check_origin' => true, 'allowed_origins' => array(), 'origin_policy_class' => 'Wrench\\Listener\\OriginPolicy', 'rate_limiter_class' => 'Wrench\\Listener\\RateLimiter'), $options);
     parent::configure($options);
 }
Example #4
0
 /**
  * Logger
  *
  * @param string $message
  * @param string $priority
  */
 public function log($message, $priority = 'info')
 {
     $this->server->log('RateLimiter: ' . $message, $priority);
 }
 /**
  * @param Server $server
  */
 public function listen(Server $server)
 {
     $server->addListener(Server::EVENT_HANDSHAKE_REQUEST, array($this, 'onHandshakeRequest'));
 }
Example #6
0
 /**
  * @see Wrench.Server::configure()
  */
 protected function configure(array $options)
 {
     $options = array_merge(array('check_origin' => true, 'allowed_origins' => array(), 'origin_policy_class' => 'Wrench\\Listener\\OriginPolicy', 'rate_limiter_class' => 'Wrench\\Listener\\RateLimiter', 'rate_limiter_options' => array('connections' => 200, 'connections_per_ip' => 5, 'requests_per_minute' => 200)), $options);
     parent::configure($options);
 }