Using fsockopen to connect to server - refused

What I'm trying to do is add support for the Votifier plugin on my website.

I sent the correct ports for the Minecraft server, tested and confirmed that they were open. Minestatus is also used to verify that the Votifier plugin is working correctly.

However, when I try to use the PHP script that I found to connect to the server, all I get is a connection failure.

<?php error_reporting(E_ALL); // Details of the vote. $str = "VOTE\n" . "TopHCSMP\n" . "SlickTheNick666\n" . "50.98.149.40\n" . time()."\n"; // Fill in empty space to make the encrypted block 256 bytes. $leftover = (256 - strlen($str)) / 2; while ($leftover > 0) { $str .= "\x0"; $leftover--; } // The public key, this is an example. $key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkFywgrx2fPXL/CPS1Gi5/a7zoTfWV9fqrhsJMzPqqC0CnLBBkg8VUiwnBVsMvhJrUT1mLvyHx5H9dobTVlE+aoxcsDRa1Yc9OAUKHspxrPswRW6/Yn85YAghOSBZfgPoXD3Q0Ng5jkJUoBUHOBtFHDUeAHi5av36iJ8dTQTSaOyAXKGdB88TOzre5cpnj5oDi/JSJ0bCJx7cgcBAO1TvOVuFMTXhygDyEVh6 o2nn8+qdDlEPXf+m+dxdkH3zWkkWjY4OittIpaHj2n8ihgPqwMPZFH1CXkoTjoSh4Fo7KtUAaAa4gt5w/thauozG25G 1s2XSigNgCDDvg4S8awmtewIDAQAB"; $key = wordwrap($key, 65, "\n", true); $key = <<<EOF -----BEGIN PUBLIC KEY----- $key -----END PUBLIC KEY----- EOF; // Encrypt the string. openssl_public_encrypt($str, $encrypted, $key); // Establish a connection to Votifier. $socket = fsockopen("50.98.149.40", "8192", $errno, $errstr, 2); if (!$socket) { die("Failed to connect to Votifier."); } // Send the contents of the encrypted block to Votifier. fwrite($socket, $encrypted); ?> 

Votifier seems to disconnect the connection, perhaps because encryption is not suitable?

+4
source share
1 answer

The error you get is connection refused , which means either the IP address or port is incorrect. They must be verified for correctness. Since you stated that you forwarded the ports, another reason for the broken code might be that you run the script and minecraft server behind the same router, and your router does not support NAT Loopback , this does not mean that with your script there is something something is wrong, but your router does not have a function.

When calculating the remaining number of errors in the code, there are more errors, you should NOT divide the sum by 2, instead, calculate it as $leftover = (256 - strlen($str)); In order to exclude that the output block is less than 256 and listens on some implementations of the Votifer protocol, the Votifer plugin does not by default check all protocol restrictions at its input.

0
source

Source: https://habr.com/ru/post/1393543/


All Articles