Re: Socket Conection

From: Afri (amnon.friling_at_citicorp.com)
Date: 06/23/04


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.



Relevant Pages

  • Re: Timeout for connect()
    ... Don't I run the risk of some kind of leak? ... socket that hasn't been opened? ... >> connection context and not create a new one? ... so I wanted to be able to cancel the connect ...
    (comp.unix.programmer)
  • Re: Socket Conection
    ... a timeout mechanism which will terminate the ... >socket command if the connection has not been established within a set ... If the connect happens before the after event, cancel ...
    (comp.lang.tcl)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #3]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... kernel socket family. ... presentation side is left to the client. ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #2]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)