Difference between revisions of "Function ping()"
Jump to navigation
Jump to search
| Line 2: | Line 2: | ||
Test connection to specified IP or URL using ICMP packet | Test connection to specified IP or URL using ICMP packet | ||
| − | <i>nil</i> ping{<code>config</code>} | + | <i>nil</i> <b>ping</b>{<code>config</code>} |
=== Parameters === | === Parameters === | ||
Revision as of 19:46, 18 April 2017
Test connection to specified IP or URL using ICMP packet
nil ping{config}
Parameters
table config
- string
addressIP or URL (without http://) to test - optional number
timeoutmaximal wait for response (in seconds) - function{response}
callbackthis function is called when response arrives or timeout is reached
Callback Parameters
table response
- boolean
successfalse = timeout reached, true = response confirmed before timeout - number
durationresponse delay (in milliseconds); if not success, duration is nil - string
errorInfoerror info in case of failure. If success, it contains "No error, return OK"
Return value
nil
Usage
-- callback function
local function logPingResult(o)
if o.success then
logf("Response lag: %dms", o.duration)
else
logf("Ping failed, reason: %s", o.errorInfo)
end
end
-- test ping www.google.com
ping{address="www.google.com", timeout=10, callback=logPingResult}
-- test ping ip address
ping{address="77.75.79.39", callback=logPingResult}
-- test ping non-existent address
ping{address="Pandora", timeout=2, callback=logPingResult}