示例#1
0
 function run($num = 1)
 {
     //初始化事件系统
     if (!$this->protocol instanceof Swoole_TCP_Server_Protocol) {
         return error(902);
     }
     //建立服务器端Socket
     $this->server_sock = $this->create("tcp://{$this->host}:{$this->port}");
     stream_set_timeout($this->server_sock, $this->timeout);
     $this->server_socket_id = (int) $this->server_sock;
     stream_set_blocking($this->server_sock, 1);
     if ($num - 1 > 0) {
         sw_spawn($num - 1);
     }
     $this->protocol->onStart();
     $this->server_loop();
 }
示例#2
0
 /**
  * 运行服务器程序
  * @return unknown_type
  */
 function run($num = 1)
 {
     //初始化事件系统
     if (!$this->protocol instanceof Swoole_TCP_Server_Protocol) {
         return error(902);
     }
     $this->init();
     //建立服务器端Socket
     $this->server_sock = $this->create("tcp://{$this->host}:{$this->port}");
     //设置事件监听,监听到服务器端socket可读,则有连接请求
     event_set($this->server_event, $this->server_sock, EV_READ | EV_PERSIST, "sw_server_handle_connect", $this);
     event_base_set($this->server_event, $this->base_event);
     event_add($this->server_event);
     if ($num - 1 > 0) {
         sw_spawn($num - 1);
     }
     $this->protocol->onStart();
     event_base_loop($this->base_event);
 }