PHP и HTML: socket_connect () [function.socket-connect]: невозможно подключиться - PullRequest
0 голосов
/ 10 декабря 2011

Я работаю над php-файлом, который подключается к моему игровому серверу и выполняет команду.Пользователи вводят свое имя пользователя в HTML-форму, которая отправляет их, и имя пользователя в php-файл, который подключается к серверу.Порт перенаправлен, и сервер готов к получению информации, но я получаю эту ошибку:

Предупреждение: socket_connect () [function.socket-connect]: невозможно подключиться [110]: истекло время ожидания подключенияв /home/moocraft/public_html/test/vote.php в строке 8 ошибка: не удалось подключиться к хосту

Вот файл 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 голосов
/ 12 декабря 2011

Попробуйте что-нибудь простое, например:

$fp = fsockopen("207.210.254.141", 4445, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\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);
}

И посмотрите, что вы получите, это может быть связано с тем, что ваш сервер слишком долго реагирует

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...