PHP和HTML:socket_connect()[function.socket-connect]:无法连接

时间:2011-12-10 08:36:23

标签: php html connection

我正在处理连接到我的游戏服务器并执行命令的php文件。用户在发送它们的HTML表单上输入用户名,并将用户名输入到连接到服务器的php文件。端口被转发,服务器已准备好接收信息,但我不断收到此错误:

警告:socket_connect()[function.socket-connect]:无法连接[110]:连接在第8行的/home/moocraft/public_html/test/vote.php中超时 错误:无法连接到主机

这是HTML文件:

<html>
<body>

<form action="vote.php" method="post">
Minecraft Username: <input type="text" name="fname" />
<input type="submit" />
</form>

</body>
</html> 

这是PHP文件:

<?php
 $HOST = "207.210.254.141"; //the ip of the bukkit server
 $password = "examplepassword1";
 $player = $_POST["fname"];
 //Can't touch this:
 $sock = socket_create(AF_INET, SOCK_STREAM, 0)
 or die("error: could not create socket\n");
 $succ = socket_connect($sock, $HOST, 4445) 
 or die("error: could not connect to host\n");
 //Authentification
 socket_write($sock, $command = md5($password)."<Password>", strlen($command) + 1)
 or die("error: failed to write to socket\n");
 //Begin custom code here.
 socket_write($sock, $command = "/Command/ExecuteConsoleCommand:give $player 264 5;", strlen($command) + 1) //Writing text/command we want to send to the server
 or die("error: failed to write to socket\n");
 socket_write($sock, $command = "$player voted for MOOcraft and earned 5 diamonds. Vote at moocraft.org;", strlen($command) + 1)
 or die("error: failed to write to socket\n");
 ?>

我无法弄清楚为什么我会继续这样做。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

尝试一些简单的事情:

$fp = fsockopen("207.210.254.141", 4445, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)
\n"; } else { $out = "GET / HTTP/1.1\r\n"; $out .= "Host: 207.210.254.141\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); }

看看你得到了什么,可能是因为你的服务器花了太长时间才回应