Esempio n. 1
0
 /**
  * @return self
  */
 protected function workOnMasterSocket()
 {
     if (@socket_recvfrom($this->masterSocket, $buffer, $this->bufferLength, MSG_DONTWAIT, $src, $spt)) {
         $client = $this->getClientByIpAndPort($src, $spt);
         if (!$client instanceof ServerClient) {
             $client = new ServerClient();
             $client->setHost($src);
             $client->setPort($spt);
             $this->clients[$client->getId()] = $client;
             $this->onConnect($client);
         }
         $client->setAttribute('timeout', microtime(true) + $this->timeoutSeconds + $this->timeoutUSeconds / 1000);
         $this->onIncoming($client, $buffer);
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * @param ServerClient $client
  * @return self
  */
 protected function workOnClientSocket(ServerClient $client)
 {
     $bytes = @socket_recv($client->getSocket(), $buffer, $this->bufferLength, 0);
     if ($bytes !== 0 && $bytes !== false) {
         $this->onIncoming($client, $buffer);
         return $this;
     }
     $this->disconnect($client, true);
     return $this;
 }