From 5ef19b3673864937d620089658b764a717e91ccc Mon Sep 17 00:00:00 2001 From: MuedeHydra Date: Mon, 24 Nov 2025 18:05:30 +0100 Subject: [PATCH] add server selection --- client.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/client.py b/client.py index ef9bef0..e28aefe 100644 --- a/client.py +++ b/client.py @@ -5,8 +5,6 @@ import datetime import threading import select -HOST = "127.0.0.1" -PORT = 65432 run = True def make_payload(name, msg): @@ -41,12 +39,24 @@ def event_handel(name, s): if __name__ == "__main__": try: - name = input("Enter name: ") + Host = input("Enter ip: (default 127.0.0.1) ") + if Host == "": + HOST = "127.0.0.1" + PORT_str = input("Enter port: (default 65432) ") + if PORT_str == "": + PORT = 65432 + else: + PORT = int(PORT_str) + + try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.connect((HOST, PORT)) + name = input("Enter name: ") + threading.Thread(target=event_handel, args=(name, s,)).start() + read_msg(s) + except ConnectionRefusedError: + print("Could not connect to the server!") - with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: - s.connect((HOST, PORT)) - threading.Thread(target=event_handel, args=(name, s,)).start() - read_msg(s) except KeyboardInterrupt: print("Exit with CTRL+C")