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.";
        }

    }



}

Link to comment
Share on other sites

@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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.