Home > Backend Development > PHP Tutorial > PHP websocket与C服务端通信的有关问题

PHP websocket与C服务端通信的有关问题

WBOY
Release: 2016-06-13 13:01:33
Original
889 people have browsed it

PHP websocket与C服务端通信的问题

	//$send_format: a4lllllalllllaala*a4<br />
	$send_format = "a4LLLLLaLLLLLaaLa".$packet_content_length."a4";<br />
	$bin_pack = pack($send_format,<br />
	                 $begin_tag,$body_tail_length,$all_packet_number,$envoy_id,$recognition_code,<br />
	                 $packet_id,$packet_request_type,$packet_body_length,<br />
	                 $packet_taskNO,$packet_middelpacketNo,$packet_minitasksequenceNo,$packet_specialkey,<br />
	                 $packet_trans_type,$packet_content_format,$packet_content_length,$packet_content,<br />
	                 $end_tag);<br />
	//----pack----------------------------------<br />
	//--------------send---------------------------<br />
	$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;<br />
	$actually_socket_write_length = @socket_write($socket,$bin_pack,$waited_socket_write_length);<br />
	if($actually_socket_write_length != $waited_socket_write_length)<br />
	{<br />
		socket_close($socket);<br />
		$result = array('EnglishToChineseReturn' => SOCKET_WRITE_ERROR);<br />
		return $result;<br />
	}
Copy after login


这是从网上找到的一段代码,实现的是PHP websocket与C/C++服务端通信的方案。
据我所知道的,C客户端和C服务端通过SOCKET通信时,直接write和read一个char数组就行,
但这段代码中pack和unpack让我很疑惑,
为什么要这么使用呢?
------解决方案--------------------
1、你是在国外吧?不知道国内的双休日吗?
2、C的一个char数组,是一个二进制的结构体。php不能直接处理,所以要用pack打包


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template