コード例 #1
0
ファイル: packer.php プロジェクト: hamily/sblack
 /**
  * 单纯发头部命令
  **/
 public function sendHeader($mid, $port)
 {
     if (!($mid = Helper::uint($mid)) || empty($port)) {
         return false;
     }
     $body = array(array($mid, API_INT));
     $buffer = '';
     //获得BODY长度
     $this->_head = "";
     $this->_body = "";
     $this->setBody($body);
     $len = $this->getBodyLen($body);
     //设置头部HEADER
     $this->setHeader($len, CLIENT_COMMAND_PHP_SEND_GIFE);
     $checkcode = $this->encryptData($len);
     //设置校验码
     $this->setCheckcode($checkcode);
     //获得全部数据
     $string = Packer::factory()->getPackage();
     //发起socket
     //if(!Socket::factory()->isConnect()){
     Socket::factory()->set_server(Core_Game::$serverIP, $port);
     Socket::factory()->connect();
     Logs::factory()->debug('packer/socketheader', Socket::factory()->get_errmsg(), Core_Game::$serverIP, $port);
     //}
     //发送内容
     $ret = Socket::factory()->write_line($string);
     $buffer = Socket::factory()->read_line_str(JW_HEADER_LEN + $len);
     Socket::factory()->close();
     $decrypt = $this->decryptData($buffer, JW_SOCKET_BACK_LEN, 'back');
     Logs::factory()->debug('packer/header', $decrypt);
     return $decrypt;
 }