examples/network/: Use getaddrinfo() result in easy way.

Instead of extracting 4th element, extact last. Much easier to remember!
pull/1916/merge
Paul Sokolovsky 2016-05-03 00:45:37 +03:00
rodzic 3944d3511f
commit c2d885501f
4 zmienionych plików z 4 dodań i 4 usunięć

Wyświetl plik

@ -9,7 +9,7 @@ def main(use_stream=False):
ai = socket.getaddrinfo("google.com", 80)
print("Address infos:", ai)
addr = ai[0][4]
addr = ai[0][-1]
print("Connect address:", addr)
s.connect(addr)

Wyświetl plik

@ -13,7 +13,7 @@ def main(use_stream=True):
ai = _socket.getaddrinfo("google.com", 443)
print("Address infos:", ai)
addr = ai[0][4]
addr = ai[0][-1]
print("Connect address:", addr)
s.connect(addr)

Wyświetl plik

@ -16,7 +16,7 @@ def main(use_stream=False):
# Binding to all interfaces - server will be accessible to other hosts!
ai = socket.getaddrinfo("0.0.0.0", 8080)
print("Bind address info:", ai)
addr = ai[0][4]
addr = ai[0][-1]
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)

Wyświetl plik

@ -17,7 +17,7 @@ def main(use_stream=True):
# Binding to all interfaces - server will be accessible to other hosts!
ai = socket.getaddrinfo("0.0.0.0", 8443)
print("Bind address info:", ai)
addr = ai[0][4]
addr = ai[0][-1]
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)