Patch #401196: Use getaddrinfo and AF_INET6 in TCP servers and clients.

This commit is contained in:
Martin v. Löwis 2001-07-24 20:34:08 +00:00
parent d61e3eab44
commit a43c2f845e
7 changed files with 160 additions and 49 deletions

View file

@ -136,8 +136,18 @@ class Telnet:
port = TELNET_PORT
self.host = host
self.port = port
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((self.host, self.port))
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
self.sock = socket.socket(af, socktype, proto)
self.sock.connect(sa)
except socket.error, msg:
self.sock.close()
self.sock = None
continue
break
if not self.sock:
raise socket.error, msg
def __del__(self):
"""Destructor -- close the connection."""