国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

wm怎么找到好友的狀態(tài)原理

phperv6
protected static function sendUdpAndRecv($address , $data)
   {
       $buffer = GatewayProtocol::encode($data);
       // 非workerman環(huán)境,使用udp發(fā)送數(shù)據(jù)
       $client = stream_socket_client("udp://$address", $errno, $errmsg);
       if(strlen($buffer) == stream_socket_sendto($client, $buffer))
       {
           // 阻塞讀
           stream_set_blocking($client, 1);
           // 1秒超時
           stream_set_timeout($client, 1);
           // 讀udp數(shù)據(jù)
           $data = fread($client, 655350);
           // 返回結(jié)果
           return json_decode($data, true);
       }
       else
       {
           throw new \Exception("sendUdpAndRecv($address, \$bufer) fail ! Can not send UDP data!", 502);
       }
   }

判斷客戶端的狀態(tài),給客戶端對應(yīng)的gateway發(fā)送udp,但是怎么找到客服端對應(yīng)的連接呢

2895 1 0
1個回答

walkor 打賞

udp數(shù)據(jù)里面包含了客戶端標示client_id,gateway收到udp數(shù)據(jù)解析得到client_id,從當前進程中可以直接得到對應(yīng)的連接,因為所有連接都存儲在一個數(shù)組中,數(shù)組的key就是client_id

  • phperv6 2015-11-10

    $this->storeClientAddress($connection->globalClientId, $address);

  • phperv6 2015-11-10

    case GatewayProtocol::CMD_IS_ONLINE:
    $connection->send((int)isset($this->_clientConnections[$data['client_id']]));

年代過于久遠,無法發(fā)表回答
??