求助 如何获取php socket 返回值

WBOY
Release: 2016-06-23 14:27:50
Original
1000 people have browsed it

使用抓包工具可以看到,就是页面获取不到返回值,怎么办??

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多秒
能不能不通的话就马上结束或者  设置超时什么的

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