Warning: socket_read(): unable to read from socket [0]: 由于套接字没有连接并且(当使用一个 sendto 调用发送数据报套接字时)没有提供地址,发送或接收数据的请求没有被接受。我建了两个文件xx.php是在服务器端执行的文件。x.php是在客户端执行的文件。
xx.php
<?php
// 设置一些基本的变量
global $lat,$lnt;
$host = "192.168.1.110";
$port = 8080;
// 设置超时时间
set_time_limit(0);
// 创建一个Socket
$commonProtocol = getprotobyname("tcp");
$socket = socket_create(AF_INET, SOCK_STREAM, $commonProtocol);//绑定Socket到端口
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
$ret = socket_listen($socket, 5);
if($ret)
{
while (true)
{
$spawn = socket_accept($socket);
if(!$spawn) break;
$output = "congratulations,you have connected server:" . $host . "!";
socket_write($spawn, $output, strlen ($output)) or die("error\n");
$input = socket_read($socket, 100000);
socket_write($spawn, $output, strlen ($input)) or die("error\n");
socket_close($spawn);
}
}
socket_close();
?>
x.php
<?php
// 设置一些基本的变量
$host = "192.168.1.110";
$port = 8080;
// 设置超时时间
set_time_limit(0);
// 创建一个Socket
$commonProtocol = getprotobyname("tcp");
$socket = socket_create(AF_INET, SOCK_STREAM, $commonProtocol);
if(!$socket) echo "can't creat socket";
//绑定Socket到端口 $result = socket_connect($socket,$host,$port);
if($result)
{
$output="abc";
socket_write($socket, $output, strlen ($output));
$input = socket_read($socket, 1024);
}
echo $input;
?>
哪位大神帮我看下,找了好多资料都没解决。
xx.php
<?php
// 设置一些基本的变量
global $lat,$lnt;
$host = "192.168.1.110";
$port = 8080;
// 设置超时时间
set_time_limit(0);
// 创建一个Socket
$commonProtocol = getprotobyname("tcp");
$socket = socket_create(AF_INET, SOCK_STREAM, $commonProtocol);//绑定Socket到端口
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
$ret = socket_listen($socket, 5);
if($ret)
{
while (true)
{
$spawn = socket_accept($socket);
if(!$spawn) break;
$output = "congratulations,you have connected server:" . $host . "!";
socket_write($spawn, $output, strlen ($output)) or die("error\n");
$input = socket_read($socket, 100000);
socket_write($spawn, $output, strlen ($input)) or die("error\n");
socket_close($spawn);
}
}
socket_close();
?>
x.php
<?php
// 设置一些基本的变量
$host = "192.168.1.110";
$port = 8080;
// 设置超时时间
set_time_limit(0);
// 创建一个Socket
$commonProtocol = getprotobyname("tcp");
$socket = socket_create(AF_INET, SOCK_STREAM, $commonProtocol);
if(!$socket) echo "can't creat socket";
//绑定Socket到端口 $result = socket_connect($socket,$host,$port);
if($result)
{
$output="abc";
socket_write($socket, $output, strlen ($output));
$input = socket_read($socket, 1024);
}
echo $input;
?>
哪位大神帮我看下,找了好多资料都没解决。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货