PHP websocket與C服務端通訊的有關問題

來源:互聯網
上載者:User
PHP websocket與C服務端通訊的問題
//$send_format: a4lllllalllllaala*a4
$send_format = "a4LLLLLaLLLLLaaLa".$packet_content_length."a4";
$bin_pack = pack($send_format,
$begin_tag,$body_tail_length,$all_packet_number,$envoy_id,$recognition_code,
$packet_id,$packet_request_type,$packet_body_length,
$packet_taskNO,$packet_middelpacketNo,$packet_minitasksequenceNo,$packet_specialkey,
$packet_trans_type,$packet_content_format,$packet_content_length,$packet_content,
$end_tag);
//----pack----------------------------------
//--------------send---------------------------
$waited_socket_write_length = BEGIN_TAG_B + BODY_TAIL_LENGTH_B + ALL_PACKET_NUMBER_B + ENVOY_ID_B + RECOGNITION_CODE_B + $body_tail_length;//20+$body_tail_length;
$actually_socket_write_length = @socket_write($socket,$bin_pack,$waited_socket_write_length);
if($actually_socket_write_length != $waited_socket_write_length)
{
socket_close($socket);
$result = array('EnglishToChineseReturn' => SOCKET_WRITE_ERROR);
return $result;
}


這是從網上找到的一段代碼,實現的是PHP websocket與C/C++服務端通訊的方案。
據我所知道的,C用戶端和C服務端通過SOCKET通訊時,直接write和read一個char數組就行,
但這段代碼中pack和unpack讓我很疑惑,
為什麼要這麼使用呢?
------解決方案--------------------
1、你是在國外吧?不知道國內的雙休日嗎?
2、C的一個char數組,是一個二進位的結構體。php不能直接處理,所以要用pack打包


  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.