Re: Socket Conection
From: Afri (amnon.friling_at_citicorp.com)
Date: 06/23/04
- Next message: Greg Shenaut: "Re: Could::someone::explain::what's::with::all::those::colons?"
- Previous message: Robert: "Re: Tk crashes with PNG images (request for reproducibility)"
- In reply to: David Gravereaux: "Re: Socket Conection"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 22 Jun 2004 19:11:06 -0700
David Gravereaux <davygrvy@pobox.com> wrote in message news:<kr0fd01grplfsv120bpmtodcanj7aa903q@4ax.com>...
> 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]]]
Great.
Thank you very much.
- Next message: Greg Shenaut: "Re: Could::someone::explain::what's::with::all::those::colons?"
- Previous message: Robert: "Re: Tk crashes with PNG images (request for reproducibility)"
- In reply to: David Gravereaux: "Re: Socket Conection"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|