tcpServer: Support specifying port number

This commit is contained in:
Nick Renieris 2022-06-26 06:30:51 +03:00
parent 740f562906
commit a416458e73
1 changed files with 6 additions and 1 deletions

View File

@ -6,8 +6,12 @@ import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 3080
if len(sys.argv) == 3:
port = int(sys.argv[2])
# Bind the socket to the port
server_address = (sys.argv[1], 3080)
server_address = (sys.argv[1], port)
print(f"Starting TCP Server with IP {server_address[0]} and Port {server_address[1]}.")
sock.bind(server_address)
@ -35,3 +39,4 @@ while True:
finally:
# Clean up the connection
connection.close()