Пример #1
0
 /**
  * Closes a client socket and removes the client from the list of clients
  *
  * @param Net_Notifier_WebSocket_Connection $client the client to close.
  *
  * @return void
  */
 protected function closeClient(Net_Notifier_WebSocket_Connection $client)
 {
     $this->log(sprintf('closing client %s ... ', $client->getIPAddress()), Net_Notifier_Logger::VERBOSITY_CLIENT);
     if ($client->getState() < Net_Notifier_WebSocket_Connection::STATE_CLOSED) {
         $client->close();
     }
     $key = array_search($client, $this->clients);
     unset($this->clients[$key]);
     $key = array_search($client, $this->listenClients);
     if ($key !== false) {
         unset($this->listenClients[$key]);
     }
     $this->log('done' . PHP_EOL, Net_Notifier_Logger::VERBOSITY_CLIENT, false);
 }
Пример #2
0
 /**
  * Disconnects this client from the server
  *
  * @return void
  */
 protected function disconnect()
 {
     // Initiate connection close. The WebSockets RFC recomends against
     // clients initiating the close handshake but we want to ensure the
     // connection is closed as soon as possible.
     $this->connection->startClose(Net_Notifier_WebSocket_Connection::CLOSE_GOING_AWAY, 'Client sent message.');
     // read server close frame
     $state = $this->connection->getState();
     $sec = intval($this->timeout / 1000);
     $usec = $this->timeout % 1000 * 1000;
     while ($state < Net_Notifier_WebSocket_Connection::STATE_CLOSED) {
         $read = array($this->socket->getRawSocket());
         $result = stream_select($read, $write = null, $except = null, $sec, $usec);
         if ($result === 1) {
             $this->connection->read(self::READ_BUFFER_LENGTH);
         } else {
             // read timed out, just close the connection
             $this->connection->close();
         }
         $state = $this->connection->getState();
     }
     $this->connection = null;
 }