Example #1
0
 /**
  * Initiates the closing handshake for a client connection
  *
  * @param Net_Notifier_WebSocket_Connection $client the client to close.
  * @param integer                           $code   optional. The WebSocket close
  *                                                  close reason code. If
  *                                                  not specified,
  *                                                  {@link Net_Notifier_WebSocket_Connection::CLOSE_NORMAL}
  *                                                  is used.
  * @param string                            $reason optional. A description
  *                                                  of why the connection
  *                                                  is being closed.
  *
  * @return void
  */
 protected function startCloseClient(Net_Notifier_WebSocket_Connection $client, $code = Net_Notifier_WebSocket_Connection::CLOSE_NORMAL, $reason = '')
 {
     $this->log(sprintf('disconnecting client from %s for reason "%s" ... ', $client->getIPAddress(), $reason), Net_Notifier_Logger::VERBOSITY_CLIENT);
     $client->startClose($code, $reason);
     $this->log('done' . PHP_EOL, Net_Notifier_Logger::VERBOSITY_CLIENT, false);
 }
Example #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;
 }