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')