Re: Socket Conection

From: Mike Tuxford (tuxfordNOSPAM_at_NORETURNearthlink.net)
Date: 06/22/04


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


Relevant Pages

  • [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)
  • Re: Socket Exception
    ... In this case the server most likely rejected your ... connection. ... Each command is a new socket connection that is opened and closed ... /// Required designer variable. ...
    (microsoft.public.win32.programmer.networks)
  • Re: attn:MVPs
    ... winsock dll to the managed .net environment. ... I have an asynchronous TCP socket that listens for data from ... The Slave should not initiate any connection requests/ send other messages ... EXCEPT the acknowledgement for the incoming messages from master, ...
    (microsoft.public.dotnet.framework)