From: ZB on
Im using "socket" for checking, if the site is "alive", just:

catch { socket $site 80 } err

....if "alive", then just "close $err" follows.

But I'm wondering, what about poor Internet connection case? Could be
possible to set longer timeout? How?
--
ZB
From: Pat Thoyts on
ZB <zbREMOVE_THIS(a)AND_THISispid.com.pl> writes:

>Im using "socket" for checking, if the site is "alive", just:
>
> catch { socket $site 80 } err
>
>...if "alive", then just "close $err" follows.
>
>But I'm wondering, what about poor Internet connection case? Could be
>possible to set longer timeout? How?
>--
>ZB

Have a look at the wiki for 'port scanning' - what you want to use is
a combination of [socket -async] and [after]

--
Pat Thoyts http://www.patthoyts.tk/
To reply, rot13 the return address or read the X-Address header.
PGP fingerprint 2C 6E 98 07 2C 59 C8 97 10 CE 11 E6 04 E0 B9 DD
From: ZB on
Dnia 27.06.2008 Pat Thoyts <cnggublgf(a)hfref.fbheprsbetr.arg> napisa�/a:

> Have a look at the wiki for 'port scanning' - what you want to use is
> a combination of [socket -async] and [after]

I'm not sure, what you mean.

If I use "-async", there will be a handle for a connection returned
immediately - therefore I'll have to test the connection different way,
for example using fileevent, like in your script.

But I've got a feeling, "async & after" gives me nothing more: just instead
of setting the timeout when testing the connection immediately (no "async"),
I'm testing the connection using "fileevent" (for example) - 2000 ms later,
but still not setting test duration. Just the testing process itself starts
2 seconds later.

I would to make it try to connect, say, 5 seconds - and not to test the
connection 5 seconds later. It's not the same.
--
ZB
From: Donal K. Fellows on
ZB wrote:
> If I use "-async", there will be a handle for a connection returned
> immediately - therefore I'll have to test the connection different way,
> for example using fileevent, like in your script.
>
> But I've got a feeling, "async & after" gives me nothing more: just instead
> of setting the timeout when testing the connection immediately (no "async"),
> I'm testing the connection using "fileevent" (for example) - 2000 ms later,
> but still not setting test duration. Just the testing process itself starts
> 2 seconds later.
>
> I would to make it try to connect, say, 5 seconds - and not to test the
> connection 5 seconds later. It's not the same.

In a normal blocking socket connection, there are two phases that can
block. The first is during the lookup of the IP address for the name
you supplied, and the second is during the actual connection forming.
The -async option allows you to return to processing your script after
the first phase; the socket will become writable (in a [fileevent]
sense) when the connection is made or fails. But the first phase can
still block (name resolution is *disgusting*; if only we could assume
that we were using DNS...) and the only way to avoid that is to supply
an IP address in the first place; Tcl parses those immediately.

So, to test whether a service is up properly, you need to do this:
1) create a socket with -async set using the numeric IP address of
the machine you're contacting
2) then set up the timeout with [after]
3) then set up a writable [fileevent]
4) now you either get a writable event or a timer event first; if
you get the writable event, you need to use [fconfigure -error] to see
if there was an error happened (IIRC)
5) you only have a successful check if you didn't timeout and didn't
get an error connecting.

Hope that explains better what's going on with this sort of checking.

Donal.
From: ZB on
Dnia 30.06.2008 Donal K. Fellows <donal.k.fellows(a)man.ac.uk> napisa�/a:

> Hope that explains better what's going on with this sort of checking.

Thanks, it's more clear - but the above means, that I cannot make it
"in 5 seconds or faster, if possible"? If I want any timeout at all,
in practice it will mean (minimal) "test duration"?

And what is the nature of the problem with name resolution? I've found on
the Pat's page ( http://www.patthoyts.tk/tclresolver/ ) a statement:

#v+
"[..] standard resolver library blocks while looking up names. This can
cause a Tcl application - and more obviously an Tk application - to hang
while a host name is resolved. Typically system resolvers use DNS to
convert a name to an address, but the system may also use files, NIS, LDAP
and other systems.

One solution is to force the use of DNS [..]"
#v-

I'm afraid, I don't understand. How the address can be resolved WITHOUT
using any DNS client :-O (because it has been described as "solution")?
Of course, when not using any local files; I meant: address _unknown_ yet.
--
ZB