Fix the client to work regardless of the IP/Port combination, default to localhost and 8181 if nothing is provided.

This commit is contained in:
Charles Descamps 2025-03-13 17:15:15 -07:00
parent 12eb4fb3f5
commit fad9f50ff8

View file

@ -2,11 +2,19 @@ import socket
import sys
import select
SERVER_HOST = 'localhost'
SERVER_PORT = 8181
BUFFER_SIZE = 1024
DEFAULT_HOST = 'localhost'
DEFAULT_PORT = 8181
def main():
if len(sys.argv) != 3:
SERVER_HOST = input(f"Enter server host (default: {DEFAULT_HOST}): ") or DEFAULT_HOST
SERVER_PORT = input(f"Enter server port (default: {DEFAULT_PORT}): ") or DEFAULT_PORT
SERVER_PORT = int(SERVER_PORT)
else:
SERVER_HOST = sys.argv[1]
SERVER_PORT = int(sys.argv[2])
# create a socket object
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try: