469,626 Members | 1,774 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

httplib and socket.getaddrinfo

I noticed the following lines from the connect() method of the
HTTPConnection class within httplib:

for res in socket.getaddrinfo(self.host, self.port, 0,
socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res

This led me to the docs that describe the socket.getaddrinfo() method:

http://www.python.org/doc/2.4.1/lib/module-socket.html

Which leads me to these questions:
1) Is it correct to infer from the "Resolves the host/port argument,
into a sequence of 5-tuples that contain all the necessary argument for
the sockets manipulation" description in the docs (in particular the
reference to 'sequence of 5-tuples') that a single host/port
combination may be associated with multiple sets of address
information?

2) In the very limited applications on which I've used
socket.getaddrinfo(), each a host/port combination that my application
passes to socket.getaddrinfo() has always returned a 1-entry list where
the list is a 5-tuple, in other words, each host/port combination has
always been associated with one set of address information. Can
someone point me to a host/port combination that, when passed to
socket.getaddrinfo() will result in socket.getaddrinfo() returning a
list of 1 entry, where each entry is a 5-tuple?

Thank you.

Dec 23 '06 #1
1 2971
At Saturday 23/12/2006 04:21, mi************@yahoo.com wrote:
>I noticed the following lines from the connect() method of the
HTTPConnection class within httplib:

for res in socket.getaddrinfo(self.host, self.port, 0,
socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res

This led me to the docs that describe the socket.getaddrinfo() method:

http://www.python.org/doc/2.4.1/lib/module-socket.html

Which leads me to these questions:
1) Is it correct to infer from the "Resolves the host/port argument,
into a sequence of 5-tuples that contain all the necessary argument for
the sockets manipulation" description in the docs (in particular the
reference to 'sequence of 5-tuples') that a single host/port
combination may be associated with multiple sets of address
information?
Yes. By example, multiple addresses for the same service are used for
load balancing. Or an IPv4 address plus an IPv6 address.
>2) In the very limited applications on which I've used
socket.getaddrinfo(), each a host/port combination that my application
passes to socket.getaddrinfo() has always returned a 1-entry list where
the list is a 5-tuple, in other words, each host/port combination has
always been associated with one set of address information. Can
someone point me to a host/port combination that, when passed to
socket.getaddrinfo() will result in socket.getaddrinfo() returning a
list of 1 entry, where each entry is a 5-tuple?
Try to relax your restrictions.

import socket
host = 'www.microsoft.com'
port = 'ftp'
for res in socket.getaddrinfo(host, port):
print res

Got 8 results:
(2, 1, 0, '', ('207.46.198.30', 21))
(2, 1, 0, '', ('207.46.198.60', 21))
(2, 1, 0, '', ('207.46.199.30', 21))
(2, 1, 0, '', ('207.46.225.60', 21))
(2, 1, 0, '', ('207.46.19.30', 21))
(2, 1, 0, '', ('207.46.19.60', 21))
(2, 1, 0, '', ('207.46.20.30', 21))
(2, 1, 0, '', ('207.46.20.60', 21))
--
Gabriel Genellina
Softlab SRL


__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Dec 23 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Bernhard Schmidt | last post: by
reply views Thread by Robert | last post: by
4 posts views Thread by Patrick Altman | last post: by
3 posts views Thread by Thomas Dybdahl Ahle | last post: by
3 posts views Thread by rhXX | last post: by
reply views Thread by Marco Bizzarri | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.