Re: Socket Conection
From: David Gravereaux (davygrvy_at_pobox.com)
Date: 06/22/04
- Next message: Greg Shenaut: "Could::someone::explain::what's::with::all::those::colons?"
- Previous message: Chengye Mao: "Re: widget for displaying pixel maps"
- In reply to: Afri: "Socket Conection"
- Next in thread: Mike Tuxford: "Re: Socket Conection"
- Reply: Mike Tuxford: "Re: Socket Conection"
- Reply: Afri: "Re: Socket Conection"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 21 Jun 2004 18:24:13 -0700
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:
set host server.blablabla.com
set port 5252
set timeoutVal 15000 ;# 15 seconds
proc SockCancel {s} {
close $s
puts "Connection on $s canceled due to timeout"
}
proc SockWritable {s timeoutToken} {
after cancel $timeoutToken
if {[set err [fconfigure $s -error]] != ""} {
puts "Got connection error for $s: $err"
close $s
}
puts "Got connection for $s"
fileevent $s writable {}
}
set s [socket -async $host $port]
fconfigure $s -blocking 0
fileevent $s writable [list SockWritable $s [after $timeoutVal [list
SockCancel $s]]]
-- David Gravereaux <davygrvy@pobox.com> [species: human; planet: earth,milkyway(western spiral arm),alpha sector]
- Next message: Greg Shenaut: "Could::someone::explain::what's::with::all::those::colons?"
- Previous message: Chengye Mao: "Re: widget for displaying pixel maps"
- In reply to: Afri: "Socket Conection"
- Next in thread: Mike Tuxford: "Re: Socket Conection"
- Reply: Mike Tuxford: "Re: Socket Conection"
- Reply: Afri: "Re: Socket Conection"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|