PHP WebSocket and C service-side communication issues

Source: Internet
Author: User
Tags php websocket
PHP WebSocket and C service-side communication problems
$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;
}


This is a piece of code found on the web that implements the PHP WebSocket communication with the C/s + + server.
As far as I know, C client and C service side through socket communication, direct write and read a char array on line,
But the pack and unpack in this code make me wonder,
Why do you use it this way?
------Solution--------------------
1. Are you in a foreign country? Do not know the domestic weekend?
2, a char array of C, is a binary structure. PHP cannot be processed directly, so pack it in packs


  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.