From a3197dbc2829850f0d61f6ef2254a7b9004bc776 Mon Sep 17 00:00:00 2001 From: Megamichi Date: Fri, 1 Dec 2023 14:34:20 +0100 Subject: [PATCH] vegbesserungen --- client.py | 4 +++- server.py | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/client.py b/client.py index 7a6e362..e6da576 100644 --- a/client.py +++ b/client.py @@ -14,12 +14,14 @@ if nickname == "": run = True def receive_message(sock): + print_lock = threading.Lock() while run: try: msg = sock.recv(1024).decode('utf-8') if not msg: break - print(f"\r{msg}\n", end='', flush=True) + with print_lock: + print(f"\r{msg}\n", end='', flush=True) except: break diff --git a/server.py b/server.py index 60c059a..2134e4c 100644 --- a/server.py +++ b/server.py @@ -16,8 +16,11 @@ def send_to_all(conn, msg): try: client.sendall(msg.encode('utf-8')) except BrokenPipeError: - print("Broken Pipe Error") - pass + print("Verbindung verloren.") + with lock: + clients.remove((conn, nick)) + conn.close() + break def handle_client(conn, addr): nick = conn.recv(1024).decode('utf-8')