Ping

Perform an IPv4 ping on a hostname or IP.

Function

void Ping(destination: string, callback: bool function(bool, int), frequency: int, destination: int);

Remarks

This function does not block; it starts the ping in the background, then calls the given callback function with the response.

If the parameters are given to Ping incorrectly, a standard JavaScript Error object will be thrown. You can check the error message with the .message property.

This function is only supported on the main event thread. (This is only relevant if you are using logical processors.)

Parameters

Name Type Description
destination string The destination. This can either be a hostname (e.g. “example.com”)
or an IPv4 address (e.g. “127.0.0.1”).
callback bool function(responseOkay: int, responseMs: int) The callback function that will be called with the result of the ping. The responseOkay parameter will be a bool – true if the remote computer responsed to the ping, false otherwise. If responseOkay is true, reponseMs will be the roundtrip time in milliseconds. Otherwise, it’s meaningless.

If the frequency parameter to Ping was given, this function must return either true or false. If it returns true, the ping will continue and this callback will be called with the result of the next ping. Otherwise the callback will not be called again.
frequency int Optional (either don’t specify it at all, or pass undefined to use the default behavior.

If this is defined, then the ping will occur repeatedly, after a delay of the given time, in milliseconds. The value must be at least 500.

Otherwise (by default) the ping will only happen once.
timeout int Optional (either don’t specify it at all, or pass undefined to use the default timeout.

The amount of time that Sym3 will wait before declaring the ping a failure due to a timeout, in milliseconds. By default, this is 8000. This value must be at least 1000.

Examples

Ping an IP once, and print a message with the results.

Ping("127.0.0.1", function(responseOkay, responseMs) {
    LogDebug(`responseOkay=${responseOkay} ms=${responseMs}`);
}); 

Ping a URL 3 times, waiting 2 seconds between pings, and timing out after 5 seconds with no response.

let counter = 0;
function MyCallback(responseOkay, responseMs) {
    LogDebug(`responseOkay=${responseOkay} ms=${responseMs}`);
    return ++counter < 3;
}
Ping("example.com", MyCallback, 2000, 5000);