PHP and HTML: socket_connect() [function.socket-connect]: unable to connect(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
这篇关于PHP 和 HTML:socket_connect() [function.socket-connect]:无法连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP 和 HTML:socket_connect() [function.socket-connect]:无法连接
基础教程推荐
- Libpuzzle 索引数百万张图片? 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01