[twsocket] Socks error

Stephen Williams SWilliams@fm.optus.net.au
Mon, 19 Jun 2000 09:19:23 +1000


> > Aha! So, can I lock typing socks server names and allow 
> only addresses ?
> > I'll also try separate DnsLookup, but when should I call it ?

Call the DnsLookup where you would have called Connect.  In the event
handler for the OnDnsLookupDone event, check the error parameter.  If
everything is ok, then get the result from the DnsResult property and set
the Addr property to that value.  Now call Connect.   If an IP address is
passed to DnsLookup, it immediately triggers the OnDnsLookupDone event with
trying to do the lookup, so you do not need to code for this separately.

> You probably can resolve socks hostname to IP address because 
> socks server
> is on your local lan and DNS will works. But you probably 
> can't resolve
> target hostname to IP address because needed DNS is behind 
> socks server.

>From my prior experience, this is how I believe the DNS system works.
Resolving hostnames to addresses should not be affected by the existence of
a SOCKS server on the local network.  When resolving an external hostname,
it is not your machine that asks the outside DNS server, but your local DNS
server.  That is, your machine asks your local DNS server to resolve a
hostname.  If your DNS server does not know the hostname (either the
hostname is not local or it is not cached information), then your DNS server
asks its parent (upstream) DNS server for the information.  The parent DNS
then does the same thing (looking at local information and cached
information) and so on until one of the DNS servers returns a result.

> Remember that a connection ALWAYS need an IP address and 
> never a hostname. A
> hostname has to be converted to an IP address. It is done by 
> DnsLookup or by
> TWSocket.Connect automatically if you forgot to do it explicitely.

Allowing Connect to implicitly do a DnsLookup results in a blocked thread
(main or otherwise) until the hostname resolution is completed.  So while it
may be simpler to just set the Addr property to the hostname and allow the
call to Connect to resolve the hostname for you, it is a much better
approach to call DnsLookup explicitly as described above.  This second
approach does not block the thread and gives your application more control
over each step of the connection process.

Steve 'Sly' Williams
IT Development
Cable & Wireless Optus Outsourcing Services
swilliams@fm.optus.net.au
------------------------------------------------------------
"What's so hard about pulling a sword out of a stone?  The real work's
already been done." -Lord Rust (Men At Arms -Discworld)
------------------------------------------------------------