How to ping?
Dar Scott
dsc at swcp.com
Wed Mar 19 16:15:01 EST 2003
Mac OS 9 or earlier, huh?
If no shell to ping, you might use appleScript to a utility.
Otherwise...
On Wednesday, March 19, 2003, at 12:55 PM, Ben Rubinstein wrote:
> Does this sound like a plan?
If you can put up with the delays in no-response failure, then you can
try it without callbacks.
You will almost always get one of three responses: Success. Error
because of rejection. Open timeout.
If using a telnet port does not interfere with the serial link you are
using then, you won't get the rejection.
Thus... Off the top of my head (this probably needs fixing; I very
rarely use blocking I/O):
function routerUp ipAddress
local routerID
put ipAddress & ":23" into routerID
open socket routerID
if result() is empty then
close socket routerID
return true
else
return false
end if
end routerUp
If you will be using the telnet for maintenance or the serial control
blocks it, then you might try an open to a non-existing port and test
between a rejection and a timeout. With a few tests you should see the
difference in result() or sysError(). Or you might discriminate on
time. (A rejection may be artificially delayed; it is delayed 9
seconds on Windows.) Note, if the router has filtering, it might be
set up to run stealth even from the inside, in which case you won't get
a rejection and this won't work.
> What I'm unclear about is whether there are
> conditions in which the open can fail without socketError?
If there are, I expect they will show up in result().
On OS X, some will show up as a socketClosed callback instead of
socketError, so I'd watch out for Mac OS.
If the old Mac takes a long time to timeout, you might want to use
callbacks and maybe send to work on timing. Also, if you want to be
doing other things at the same time, you don't want to use blocking
calls. (I very rarely use blocking calls.) If you are checking dozens
of routers, then you will want to use callbacks.
> And if so is
> there likely to be a problem if this is repeated thousands of times a
> day?
There should not be, but there might be if your system has a memory
leak or a port leak. If you run into problems, you might automate a
reboot every night.
> Also, the docs are unclear as to how I can access the ID that I can
> optionally specify when opening the socket. Presumably this is
> appended to
> the parameter to the callback message?
Yes.
> (Forgive me if your response is to
> "try it and you'll see", but I'm no longer at the office.)
To be comfortable with this you might want to look yourself at
result(), sysError(), and time for several cases, anyway. As a wimp, I
would.
Dar Scott
More information about the use-livecode
mailing list