我正在运行
$data = socket_read($socket, 2048, PHP_BINARY_READ);
应该返回一个像这样的字符串
// $data == ' 1840 kg G 008765 A '
但它会返回
Original response: HTTP/1.1 200 OK
Date: Wed, 19 Feb 2003 09:00:00 GMT
Server: MoxaHttp/1.0
Pragma: no-cache
Cache-Control: no-cache
Content-type: text/html
Content-length: 450
看起来像是返回数据的标题。
socket_send配置正确,我们有其他客户端具有相同的设置,并返回正确的值。
你能说出问题是什么,为什么我没有得到预期的字符串?
更新:
我多次重复执行socket_read()以读取完整的字符串:
Original response: HTTP/1.1 200 OK
Date: Wed, 19 Feb 2003 09:00:00 GMT
Server: MoxaHttp/1.0
Pragma: no-cache
Cache-Control: no-cache
Content-type: text/html
Content-length: 450
Set-Cookie: ChallID=1656
<HTML><HEAD><TITLE>NPort Web Console</TITLE></HEAD> <FRAMESET rows=57,1* frameborder=NO> <FRAME name=top scrolling=NO target=contents src=top.htm noresize> <FRAMESET cols=200,*> <FRAME name=contents target=main src=contents.htm> <FRAME name=main src=main.htm marginwidth=0 marginheight=0 scrolling=auto> </FRAMESET> <NOFRAMES><BODY background=bg.gif><P>This page uses frame, but your browser doesn't support.</P></BODY> </NOFRAMES> </FRAMESET></HTML>
所以看起来它会返回一些不同的东西,这些东西可以被其他程序读取。
答案 0 :(得分:0)
您尝试过吗?:
echo "Reading response:\n\n";
$buf = 'This is my buffer.';
if (false !== ($bytes = socket_recv($socket, $buf, 2048, MSG_WAITALL))) {
echo "Read $bytes bytes from socket_recv(). Closing socket...";
} else {
echo "socket_recv() failed; reason: " . socket_strerror(socket_last_error($socket)) . "\n";
}
socket_close($socket);