examples/network/: Use getaddrinfo() result in easy way.
Instead of extracting 4th element, extact last. Much easier to remember!
This commit is contained in:
parent
3944d3511f
commit
c2d885501f
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user