Jump to content

Can't Connect To Server on Remote Server Script only works on Local Server


ianp

Recommended Posts

I programmed a site for a friend and it worked fine the only problem is on the remote server it cant connect to the remote server.

This is the script I am using

class MCServerStatus {


    public $server;
    public $online, $motd, $online_players, $max_players;
    public $error = "OK";



    function __construct($url, $port = '25565') {

        $this->server = array(
            "url" => $url,
            "port" => $port
        );

        if ( $sock = @stream_socket_client('tcp://'.$url.':'.$port, $errno, $errstr, 1) ) {

            $this->online = true;

            fwrite($sock, "\xfe");
            $h = fread($sock, 2048);
            $h = str_replace("\x00", '', $h);
            $h = substr($h, 2);
            $data = explode("\xa7", $h);
            unset($h);
            fclose($sock);

            if (sizeof($data) == 3) {
                $this->motd = $data[0];
                $this->online_players = (int) $data[1];
                $this->max_players = (int) $data[2];
            }
            else {
                $this->error = "Cannot retrieve server info.";
            }

        }
        else {
            $this->online = false;
            $this->error = "Cannot connect to server.";
        }

    }



}

@scootstah, I had a dedicated server to godaddy, I've had to create a ssh tunnel to connect remotely to MySQL.

 

He's not connecting to MySQL, he appears to be connecting to a game server with a socket.

 

As for you, you probably didn't have the MySQL config set properly. You have to explicitly allow remote connections.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.