Connect Example with IPv6 Awareness : IPv6 : Network PYTHON TUTORIALS


PYTHON TUTORIALS » Network » IPv6 »

 

Connect Example with IPv6 Awareness


import socket, sys

def getaddrinfo_pref(host, port, socktype, familypreference = socket.AF_INET):
    results = socket.getaddrinfo(host, port, 0, socktype)
    for result in results:
        if result[0== familypreference:
            return result
    return results[0]

host = "127.0.0.1"
port = '80'

c = getaddrinfo_pref(host, port, socket.SOCK_STREAM)
print c[4]
s = socket.socket(c[0], c[1])
s.connect(c[4])
s.sendall("HEAD / HTTP/1.0nn")

while 1:
    buf = s.recv(4096)
    if not len(buf):
        break
    sys.stdout.write(buf)



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Network
» IPv6