httplib and socket.getaddrinfo

Discussion in 'Python' started by mirandacascade@yahoo.com, Dec 23, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. At Saturday 23/12/2006 04:21, 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
    Gabriel Genellina, Dec 23, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bernhard Schmidt

    result sorting in socket.getaddrinfo?

    Bernhard Schmidt, Oct 9, 2004, in forum: Python
    Replies:
    0
    Views:
    362
    Bernhard Schmidt
    Oct 9, 2004
  2. Thomas Dybdahl Ahle

    Kill thread or at least socket.getaddrinfo

    Thomas Dybdahl Ahle, Mar 26, 2007, in forum: Python
    Replies:
    3
    Views:
    1,495
    Chris Mellon
    Apr 10, 2007
  3. RajNewbie
    Replies:
    2
    Views:
    669
    RajNewbie
    Dec 1, 2008
  4. Replies:
    9
    Views:
    192
  5. Glen Holcomb
    Replies:
    0
    Views:
    202
    Glen Holcomb
    Sep 12, 2008
Loading...

Share This Page