Re: Socket Conection
From: Mike Tuxford (tuxfordNOSPAM_at_NORETURNearthlink.net)
Date: 06/22/04
- Next message: art morel: "Re: tcltk.com - dead url on front page"
- Previous message: Greg Shenaut: "Re: Could::someone::explain::what's::with::all::those::colons?"
- In reply to: David Gravereaux: "Re: Socket Conection"
- Next in thread: Donal K. Fellows: "Re: Socket Conection"
- Reply: Donal K. Fellows: "Re: Socket Conection"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 22 Jun 2004 15:58:05 GMT
David Gravereaux <davygrvy@pobox.com> wrote:
:amnon.friling@citicorp.com (Afri) wrote:
:
:>Hi
:>
:>I am looking for a method to monitor the creation of a client socket
:>connection. Meaning, a timeout mechanism which will terminate the
:>socket command if the connection has not been established within a set
:>up time.
:>
:>Thanks
:>afri
:
:First, use the -async option to connect. Second, setup an after event to
:close the socket. If the connect happens before the after event, cancel
:it. That's the basics. Note that if there is a DNS delay, the lookup is
:blocking and can't be canceled. It would look something like this;
:untested:
... [a lot of good example code clipped to pursue a side issue]
On a side issue, here's my current kludge for the 'DNS
Blocking Problem'. My thought is to resolve a hostname to
an IP via an external exec'd process before trying to create
the socket, The theory being that it's better to take a
little longer but leaving the Tk GUI available.
Mine is relying upon /usr/bin/host Any other ideas out
there not covered on the relevant Wiki page? Or ideas
good/bad about my kludge?
# this is used to avoid Tk freezing from "The DNS
# blocking problem" see: http://wiki.tcl.tk/2929
# caveats: If hostname has multiple IPs you always get first one.
# Written only for "http://" urls and not others.
proc resolve_host {url} {
upvar #0 ::gdata::resolver resolver
# if none defined return what we got
# current version can only use /usr/bin/host
if {$resolver == ""} {
return $url
}
set hostname [string trimleft $url "http://"]
set hostname [string range $hostname 0 \
[expr {[string first "/" $hostname]-1}]]
set path [string range $hostname \
[string first "/" $hostname] end]
set result [split [exec $resolver $hostname] \n]
set ip ""
foreach line $result {
if {[string match "*has address*" $line]} {
set ip [lindex $line end]
break
}
}
if {$ip ne ""} {
return "http://$ip$path"
} else {
# calling proc tests for "none"
return none
}
}
-- _ _ ____ //\/\ike ||uxford tuxford@earthlink.net
- Next message: art morel: "Re: tcltk.com - dead url on front page"
- Previous message: Greg Shenaut: "Re: Could::someone::explain::what's::with::all::those::colons?"
- In reply to: David Gravereaux: "Re: Socket Conection"
- Next in thread: Donal K. Fellows: "Re: Socket Conection"
- Reply: Donal K. Fellows: "Re: Socket Conection"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|