Commit c2d88550 authored by Paul Sokolovsky's avatar Paul Sokolovsky

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

Instead of extracting 4th element, extact last. Much easier to remember!
parent 3944d351
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment