Author Topic: Pinging a server using TS?  (Read 867 times)

How can I ping a server using TS to check if it's up?
I want it to return 0 if it's down.

First off, you won't be able to write a function that returns 0 if the server is down. Servers are determined as 'down' when something like 2,000-5,000 milliseconds have passed and the server hasn't replied, so if you wanted to wait until that had passed before returning 0 the game would simply freeze for that long.

So you need an asynchronous option, which is totally possible. That just means it won't return true/false, you'll have a callback to handle whether it's up or down.

Code: [Select]
function pingServer(%ip) {
    pingSingleServer(%ip, 4096);
}

package handlePing {
     function onSimplePingReceived(%host,%ping,%index) {
        if(%index == 4096) return myPingServerUp(%ping);
        Parent::onSimplePingReceived(%host,%ping,%index);
    }
    function onSimplePingTimeout(%host,%index) {
        if(%index == 4096) return myPingServerDown(%ping);
        Parent::onSimplePingTimeout(%host,%index);
    }
};

function myPingServerUp(%ping) {
    // do your stuff
}

function myPingServerDown(%ping) {
    // do your stuff
}

pingServer("127.0.0.1:24000");

Servers are determined as 'down' when something like 2,000-5,000 milliseconds have passed and the server hasn't replied
Sorry for the unrelated reply here but I once got a ping-back from a server a whole 5 minutes after the initial ping... what on earth would cause that?

Sorry for the unrelated reply here but I once got a ping-back from a server a whole 5 minutes after the initial ping... what on earth would cause that?

The server must have been blocked by something. No idea what.

Thank you!
Would it be okay to copy-paste that and credit you in a script I'm writing?

No credit needed. Go for it.

Just remember to activate the package. I forgot to do that.