PHP 和 HTML:socket_connect() [function.socket-connect]:无法连接
我正在处理一个连接到我的游戏服务器并执行命令的 php 文件.用户在发送他们的 HTML 表单上输入他们的用户名,并将用户名输入到连接到服务器的 php 文件中.端口已转发,服务器已准备好接收信息,但我不断收到此错误:
警告:socket_connect() [function.socket-connect]:无法连接 [110]:第 8 行/home/moocraft/public_html/test/vote.php 中的连接超时错误:无法连接到主机
这是 HTML 文件:
<html><身体><form action="vote.php" method="post">我的世界用户名:<input type="text" name="fname"/><输入类型=提交"/></表格></身体></html>
这是 PHP 文件:
", strlen($command) + 1)or die("错误: 无法写入套接字
");//从这里开始自定义代码.socket_write($sock, $command = "/Command/ExecuteConsoleCommand:give $player 264 5;", strlen($command) + 1)//编写我们要发送到服务器的文本/命令or die("错误: 无法写入套接字
");socket_write($sock, $command = "$player 为 MOOcraft 投票,获得 5 颗钻石.在 moocraft.org 投票;", strlen($command) + 1)or die("错误: 无法写入套接字
");?>
我不明白为什么我一直收到这个.非常感谢任何帮助.
解决方案尝试一些简单的方法,例如:
<上一页>$fp = fsockopen("207.210.254.141", 4445, $errno, $errstr, 30);如果 (!$fp) {echo "$errstr ($errno)";} 别的 {$out = "GET/HTTP/1.1 ";$out .= "主机:207.210.254.141 ";$out .= "连接:关闭 ";fwrite($fp, $out);而 (!feof($fp)) {回声 fgets($fp, 128);}fclose($fp);}
看看你得到了什么,这可能是由于你的服务器响应时间过长
I am working on a php file that connects to my game server and executes a command. The users enter their username on a HTML form that sends them and the username to a php file that connects to the server. The port is forwarded and the server is ready to receive the info, but I keep getting this error:
Warning: socket_connect() [function.socket-connect]: unable to connect [110]: Connection timed out in /home/moocraft/public_html/test/vote.php on line 8 error: could not connect to host
Here is the HTML file:
<html>
<body>
<form action="vote.php" method="post">
Minecraft Username: <input type="text" name="fname" />
<input type="submit" />
</form>
</body>
</html>
Here is the PHP file:
<?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
");
$succ = socket_connect($sock, $HOST, 4445)
or die("error: could not connect to host
");
//Authentification
socket_write($sock, $command = md5($password)."<Password>", strlen($command) + 1)
or die("error: failed to write to socket
");
//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
");
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
");
?>
I can't figure out why I keep getting this. Any help is greatly appreciated.
解决方案Try something simple like:
$fp = fsockopen("207.210.254.141", 4445, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)
"; } else { $out = "GET / HTTP/1.1 "; $out .= "Host: 207.210.254.141 "; $out .= "Connection: Close "; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); }
And see what do you get, it might be due to the reason that your server is taking too long to respond
相关文章