示例#1
0
 /**
  * Setup the Socket manager to use inet sockets using the TCP protocol
  * @return void
  */
 protected function setup()
 {
     $socketOptions = array('domain' => AF_INET, 'type' => SOCK_STREAM, 'protocol' => SOL_TCP, 'address' => $this->address, 'port' => $this->port, 'backlog' => $this->maxClients);
     $this->masterSocket = SocketFactory::create($socketOptions)->bind()->listen();
     # todo make this more dependency injection
     $this->clients = new SocketManager($this->masterSocket, $this->maxClients, $this->commands, $this->handler);
 }
示例#2
0
 /**
  * Accept a new client socket for reading
  * 
  * @return SocketManager the current object for chaining
  */
 protected function accept()
 {
     if (in_array($this->masterSocket, $this->read)) {
         $newClient = SocketFactory::create($this->masterSocket);
         if ($welcome = $this->handler->onConnect()) {
             $newClient->write($welcome);
         }
         $this->clients[] = $newClient;
     }
     return $this;
 }
示例#3
0
 /**
  * Internal helper function to get a writable socket
  * 
  * @return MasterSocket a writable socket
  */
 protected static function getSocket()
 {
     $socketOptions = array('domain' => AF_INET, 'type' => SOCK_STREAM, 'protocol' => SOL_TCP, 'address' => static::$address, 'port' => static::$port);
     static::$socket = SocketFactory::create($socketOptions)->connect();
     return static::$socket;
 }