Ejemplo n.º 1
0
 /**
  * 踢掉某个网关的socket
  * @param string $local_ip
  * @param int $local_port
  * @param int $socket_id
  * @param string $message
  * @param int $client_id
  */
 protected static function kickAddress($local_ip, $local_port, $socket_id)
 {
     $pack = new GatewayProtocol();
     $pack->header['cmd'] = GatewayProtocol::CMD_KICK;
     $pack->header['local_ip'] = $local_ip;
     $pack->header['local_port'] = $local_port;
     $pack->header['socket_id'] = $socket_id;
     if (null !== Context::$client_ip) {
         $pack->header['client_ip'] = Context::$client_ip;
         $pack->header['client_port'] = Context::$client_port;
     }
     $pack->header['client_id'] = 0;
     $pack->body = '';
     return self::sendToGateway("{$pack->header['local_ip']}:{$pack->header['local_port']}", $pack->getBuffer());
 }
Ejemplo n.º 2
0
 /**
  * 随机抽取一个与BusinessWorker的长连接,将数据发给一个BusinessWorker
  * @param int $cmd
  * @param int $socket_id
  * @param string $body
  */
 protected function sendToWorker($cmd, $socket_id, $body = '')
 {
     $address = $this->getRemoteAddress($socket_id);
     if ($address) {
         list($client_ip, $client_port) = explode(':', $address, 2);
     } else {
         $client_ip = 0;
         $client_port = 0;
     }
     $pack = new GatewayProtocol();
     $pack->header['cmd'] = $cmd;
     $pack->header['local_ip'] = $this->lanIp;
     $pack->header['local_port'] = $this->lanPort;
     $pack->header['socket_id'] = $socket_id;
     $pack->header['client_ip'] = $client_ip;
     $pack->header['client_port'] = $client_ip;
     $pack->header['uid'] = $this->getUidByFd($socket_id);
     $pack->body = $body;
     $pack->ext_data = $this->socketSessionMap[$pack->header['socket_id']];
     return $this->sendBufferToWorker($pack->getBuffer());
 }
Ejemplo n.º 3
0
 /**
  * 随机抽取一个与BusinessWorker的长连接,将数据发给一个BusinessWorker
  * @param int $cmd
  * @param int $socket_id
  * @param string $body
  */
 protected function sendToWorker($cmd, $socket_id, $body = '')
 {
     $pack = new GatewayProtocol();
     $pack->header['cmd'] = $cmd;
     $pack->header['local_ip'] = $this->lanIp;
     $pack->header['local_port'] = $this->lanPort;
     $pack->header['socket_id'] = $socket_id;
     $pack->header['client_ip'] = $this->connRemoteAddressMap[$socket_id]['ip'];
     $pack->header['client_port'] = $this->connRemoteAddressMap[$socket_id]['port'];
     $pack->header['client_id'] = $this->getClientIdByFd($socket_id);
     $pack->body = $body;
     $pack->ext_data = $this->connSessionMap[$pack->header['socket_id']];
     return $this->sendBufferToWorker($pack->getBuffer());
 }
Ejemplo n.º 4
0
 /**
  * 更新session
  * @param int $uid
  * @param string $session_str
  */
 public static function updateSocketSession($socket_id, $session_str)
 {
     $pack = new GatewayProtocol();
     $pack->header['cmd'] = GatewayProtocol::CMD_UPDATE_SESSION;
     $pack->header['socket_id'] = Context::$socket_id;
     $pack->ext_data = (string) $session_str;
     return self::sendToGateway(Context::$local_ip . ':' . Context::$local_port, $pack->getBuffer());
 }