Skip to content

Commit c2d8855

Browse files
committed
examples/network/: Use getaddrinfo() result in easy way.
Instead of extracting 4th element, extact last. Much easier to remember!
1 parent 3944d35 commit c2d8855

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

examples/network/http_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def main(use_stream=False):
99

1010
ai = socket.getaddrinfo("google.com", 80)
1111
print("Address infos:", ai)
12-
addr = ai[0][4]
12+
addr = ai[0][-1]
1313

1414
print("Connect address:", addr)
1515
s.connect(addr)

examples/network/http_client_ssl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def main(use_stream=True):
1313

1414
ai = _socket.getaddrinfo("google.com", 443)
1515
print("Address infos:", ai)
16-
addr = ai[0][4]
16+
addr = ai[0][-1]
1717

1818
print("Connect address:", addr)
1919
s.connect(addr)

examples/network/http_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def main(use_stream=False):
1616
# Binding to all interfaces - server will be accessible to other hosts!
1717
ai = socket.getaddrinfo("0.0.0.0", 8080)
1818
print("Bind address info:", ai)
19-
addr = ai[0][4]
19+
addr = ai[0][-1]
2020

2121
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
2222
s.bind(addr)

examples/network/http_server_ssl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def main(use_stream=True):
1717
# Binding to all interfaces - server will be accessible to other hosts!
1818
ai = socket.getaddrinfo("0.0.0.0", 8443)
1919
print("Bind address info:", ai)
20-
addr = ai[0][4]
20+
addr = ai[0][-1]
2121

2222
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
2323
s.bind(addr)

0 commit comments

Comments
 (0)