[Twisted-Python] twisted.names.client.getHostByName() vs. reactor.resolve()

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Sun Jul 13 11:47:22 MDT 2014


On 02:16 pm, rutt.4 at osu.edu wrote:
>Hi,
>
>I need to do a DNS resolution of a hostname to an IPv4 address in order 
>to
>then send out a UDP packet via twisted’s APIs.  There appears to be 2 
>ways
>to do this.  Is it better to use twisted.names.client.getHostByName(), 
>or
>is it better to use reactor.resolve()?  Is there a bias for one over 
>the
>other?  Is one deprecated and the other isn’t?

`reactor.resolve` is "do something, who knows what really, to turn a 
name into an IPv4 address".

`twisted.names.client.getHostByName` is "use Twisted's DNS client 
implementation to issue the necessary DNS queries to resolve a name into 
an IPv4 or IPv6 address".

If you definitely only care about IPv4 then `reactor.resolve` is going 
to work correctly in more situations.  By default it will use the system 
resolver.  Therefore, by default, you will get whatever weird 
configuration the system resolver has been given (for example: use 
/etc/hosts or use mDNS or use NIS or YP or whatever.

Note that `reactor.resolve` is a pluggable interface and application 
code is allowed to substitute an alternate resolver implementation which 
may work in some other way.

If you care specifically about DNS or you need IPv6 or you have a reason 
to want to avoid threads (which, by default, `reactor.resolve` uses), 
you might prefer to use `twisted.names.client` directly.

Most applications will probably be okay with `reactor.resolve` but I 
imagine this could change as IPv6 use gradually becomes more widespread.

Jean-Paul




More information about the Twisted-Python mailing list