所以我试图让在托管网站(姑且称之为online.com),以能够从我的Apache本地(WAMP)抓住一些文本文件。Socket连接到本地主机已超时
然而,当我运行的代码online.com负载了一会儿,然后提出错误100(超时)。我不知道为什么。
我使用套接字来做到这一点。我在PC的防火墙上将online.com的ip列入了白名单。我已将侦听端口添加到Apache服务器。我已经完成了端口转发(尽管我没有100%确定我是否已经完成了这项工作)。
以下是上述的更具象征意义的表示。
端口转发
online.com's IP = X, port = 80
local host's IP = (used ipconfig) IPV4 Address, port = Y
阿帕奇
Listening on port Y
白名单
Added IP X
当我运行php脚本online.com
if (!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg \n");
}
echo "Socket created \n";
// Connect socket to remote server
**if (!socket_connect($sock, 'IP X', PORTY))**
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not connect: [$errorcode] $errormsg \n");
}
echo "Connection established \n";
$message = "GET/PRCC /HTTP/1.1 \r\n\r\n";
// Send the message to the server
if (!socket_send($sock, $message, strlen($message) , 0))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not send data: [$errorcode] $errormsg \n");
}
echo "Message send successfully \n";
$buf = "";
// Now receive reply from server
if (socket_recv($sock, $buf, 2045, MSG_WAITALL) === FALSE)
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not receive data: [$errorcode] $errormsg \n");
}
// print the received message
echo $buf . "this is the buffer";
socket_close($sock);
该行是问题的原因。
任何关于什么可能是错误的建议将不胜感激。
什么是错误信息?是否die()在连接失败后返回特定错误? – gladiola