Exemple #1
0
 /**
  * 关闭服务器程序
  * @return unknown_type
  */
 function shutdown()
 {
     //关闭服务器端
     sw_socket_close($this->server_sock);
     //关闭事件循环
     $this->protocol->onShutdown($this);
 }
Exemple #2
0
 function close($client_id)
 {
     sw_socket_close($this->client_sock[$client_id]);
     $this->client_sock[$client_id] = null;
     unset($this->client_sock[$client_id]);
     $this->protocol->onClose($client_id);
 }
Exemple #3
0
 /**
  * 关闭服务器程序
  * @return unknown_type
  */
 function shutdown()
 {
     //关闭服务器端
     sw_socket_close($this->server_sock, $this->server_event);
     //关闭事件循环
     event_base_loopexit($this->base_event);
     $this->protocol->onShutdown();
 }
 function accept()
 {
     $client_socket = stream_socket_accept($this->server_sock);
     $client_socket_id = (int) $client_socket;
     stream_set_blocking($client_socket, $this->client_block);
     $this->client_sock[$client_socket_id] = $client_socket;
     $this->client_num++;
     if ($this->client_num > $this->max_connect) {
         sw_socket_close($client_socket);
         return false;
     } else {
         //设置写缓冲区
         stream_set_write_buffer($client_socket, $this->write_buffer_size);
         return $client_socket_id;
     }
 }
Exemple #5
0
 /**
  * 关闭某个客户端
  * @return unknown_type
  */
 function close($client_id)
 {
     sw_socket_close($this->client_sock[$client_id], $this->client_event[$client_id]);
     unset($this->client_sock[$client_id], $this->client_event[$client_id]);
     $this->protocol->onClose($client_id);
     $this->client_num--;
 }