示例#1
0
 protected function parsePacket($str, &$sessionId, &$serverInfo)
 {
     if ($arr = json_decode($str, true)) {
         $sessionId = $serverInfo = null;
         if (isset($arr[$this->sessionKey]) && $arr[$this->sessionKey]) {
             $sessionId = $arr[$this->sessionKey];
         }
         if ($packet = Packet::getPacketFromArray($arr)) {
             return $packet;
         }
     }
     return false;
 }
示例#2
0
文件: Server.php 项目: lscgzwd/jegarn
 protected function parsePacket($str, &$sessionId, &$serverInfo)
 {
     $sessionId = $serverInfo = null;
     if ($arr = ConvertUtil::unpack($str)) {
         if (isset($arr[$this->serverKey])) {
             if (!($serverInfo = $this->getRegister($arr[$this->serverKey]))) {
                 return false;
             }
         }
         if (isset($arr[$this->sessionKey]) && $arr[$this->sessionKey]) {
             $sessionId = $arr[$this->sessionKey];
         }
         if ($packet = Packet::getPacketFromArray($arr)) {
             return $packet;
         }
     }
     return false;
 }
示例#3
0
 public function sendToRemoteServer(Session $session, Packet $packet)
 {
     $data = $packet->convertToArray();
     $data[$this->serverKey] = $this->serverId;
     $packetStr = ConvertUtil::pack($data);
     $ret = SocketManager::getInstance()->sendClientMessage($session->getServerAddress(), $session->getServerPort(), pack('N', strlen($packetStr)) . $packetStr, $this->config);
     if (false === $ret) {
         Logger::addInfo('send remote server failed, dispatch again (fd:' . $session->getFd() . ') ');
         $session->setReachable(false);
         $this->dispatchSend($session, $packet);
     }
 }
示例#4
0
文件: client.php 项目: lscgzwd/jegarn
function serializePacket(Packet $packet)
{
    $data = ['from' => $packet->getFrom(), 'to' => $packet->getTo(), 'type' => $packet->getType(), 'content' => $packet->getContent()];
    $data['session_id'] = G::$sessionId;
    echo "-----------SEND--------------------------------\n";
    echo 'send: ', json_encode($data, JSON_UNESCAPED_UNICODE), "\n";
    $data = ConvertUtil::pack($data);
    $data = pack('N', strlen($data)) . $data;
    echo "packet length: ", strlen($data) . "\n\n";
    return $data;
}