如何将数据从 PHP 页面发送到 TCP 端口?
<?php
// parameters to connect to server
$ip = "192.168.1.3";
$port = "59995";
$data = "Hello";
$output = "";
// Create a TCP Stream Socket
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
// Connect to the server.
$result = socket_connect($socket, $ip, $port);
// Write to socket!
socket_write($socket, $data, strlen($data));
// Read from server
do
{
$line =@socket_read($socket,2048);
echo $line. "\n";
}
while ($data != "0");
// Close and return.
socket_close($socket);
?>
我正在使用它,但我无法接收任何数据!另外,您知道我如何为此设置超时吗?
问题是什么?