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

查看:2634
本文介绍了PHP和HTML:socket_connect()[function.socket-connect]:无法连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个php文件,连接到我的游戏服务器并执行一个命令。用户在发送它们的HTML表单上输入用户名,并将用户名输入到连接到服务器的php文件。端口被转发并且服务器准备好接收信息,但是我一直收到这个错误:

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:

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

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

这是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");
 ?>

我不知道为什么我一直得到这个。非常感谢任何帮助。

I can't figure out why I keep getting this. Any help is greatly appreciated.

推荐答案

尝试一些简单的:


$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); }

看看你得到了什么,这可能是由于你的服务器响应时间太长

And see what do you get, it might be due to the reason that your server is taking too long to respond

这篇关于PHP和HTML:socket_connect()[function.socket-connect]:无法连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆