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