欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

求助 如何获取php socket 返回值

程序员文章站 2024-01-03 22:35:16
...
使用抓包工具可以看到,就是页面获取不到返回值,怎么办??

function Send_socket_connect($service_port, $address, $in) {

header("Connection: close");
header("Content-Encoding: none");
ob_start();
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("could not create socket!");

$result = socket_connect($socket, $address, $service_port) or die("could not connect with" . $address);

socket_write($socket, $in, strlen($in));
$response = '';
do {
$buffer = socket_read($socket, 1024, PHP_NORMAL_READ);
$response .= $buffer;
} while (!empty($buffer));


socket_close($socket);
return response;
}

$str = Send_socket_connect(5000, "10.0.1.21", "[GetOutPutNum]");
echo $str;
?>

回复讨论(解决方案)

这是抓包工具得到的

服务器端怎么写的?给你返回值了吗?

已解决,返回值要以 \n结束才能获取 ,
新的问题。。。还是以上代码

$result = socket_connect($socket, $address, $service_port) or die("could not connect with" . $address);

返回 could not connect with $address 最少要20多秒
能不能不通的话就马上结束或者 设置超时什么的

上一篇:

下一篇: