add server selection

This commit is contained in:
MuedeHydra 2025-11-24 18:05:30 +01:00
parent 640dbc0081
commit 5ef19b3673

View File

@ -5,8 +5,6 @@ import datetime
import threading import threading
import select import select
HOST = "127.0.0.1"
PORT = 65432
run = True run = True
def make_payload(name, msg): def make_payload(name, msg):
@ -41,12 +39,24 @@ def event_handel(name, s):
if __name__ == "__main__": if __name__ == "__main__":
try: 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: except KeyboardInterrupt:
print("Exit with CTRL+C") print("Exit with CTRL+C")