tcpServer: Handle connection reset

This commit is contained in:
Nick Renieris 2022-06-25 03:48:06 +03:00
parent 0bfd7a70b2
commit d1e4466fba

View file

@ -22,12 +22,16 @@ while True:
print(f'Switch Connected! IP: {client_address[0]} Port: {client_address[1]}')
while True:
data = connection.recv(1024)
if data:
print(data.decode("utf-8"), end='', flush=True)
else:
print(f'Connection Terminated.')
break
except ConnectionResetError:
print("Connection reset")
finally:
# Clean up the connection
connection.close()