Skip to content

Commit f5a86d9

Browse files
P2P: Handle abrupt connection closes and give "nice" messages.
This can happen, for example when a peer presses CTRL+C. This makes the program crash for the other user, but now we catch those exception print "nice" (relatively nice :D) error messages. Closes #1
1 parent 7f92a85 commit f5a86d9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

P2P/Server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ def check_if_incoming_data(self):
2424
# print(e)
2525
# No data to read
2626
return tuple([00, ''])
27-
27+
except (ConnectionResetError, ValueError) as e:
28+
## ValueError is raised from parse_received_data
29+
print("\n\nUh-oh. looks like peer has closed the connection :(")
30+
exit()
2831

2932
def send_request(self, request):
3033
self.socket.send(request.get_type_byte() + request.get_message_bytes())

0 commit comments

Comments
 (0)