vegbesserungen

This commit is contained in:
Michael S. 2023-12-01 14:34:20 +01:00
parent 11396ef2cf
commit a3197dbc28
2 changed files with 8 additions and 3 deletions

View file

@ -14,11 +14,13 @@ if nickname == "":
run = True run = True
def receive_message(sock): def receive_message(sock):
print_lock = threading.Lock()
while run: while run:
try: try:
msg = sock.recv(1024).decode('utf-8') msg = sock.recv(1024).decode('utf-8')
if not msg: if not msg:
break break
with print_lock:
print(f"\r{msg}\n", end='', flush=True) print(f"\r{msg}\n", end='', flush=True)
except: except:
break break

View file

@ -16,8 +16,11 @@ def send_to_all(conn, msg):
try: try:
client.sendall(msg.encode('utf-8')) client.sendall(msg.encode('utf-8'))
except BrokenPipeError: except BrokenPipeError:
print("Broken Pipe Error") print("Verbindung verloren.")
pass with lock:
clients.remove((conn, nick))
conn.close()
break
def handle_client(conn, addr): def handle_client(conn, addr):
nick = conn.recv(1024).decode('utf-8') nick = conn.recv(1024).decode('utf-8')