Skip to content

Commit

Permalink
Add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdwetering committed Mar 30, 2024
1 parent 357f30a commit 57e604a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ynca/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class YncaCommandHandler(socketserver.StreamRequestHandler):
client.
"""

timeout = 40 # Receiver disconnects after 40 seconds of no traffic

def __init__(self, request, client_address, server: YncaServer):
self.store = server.store
self.disconnect_after_receiving_num_commands = (
Expand Down Expand Up @@ -283,9 +285,14 @@ def handle(self):

print(f"--- Client connected from: {self.client_address[0]}")
while True:
bytes_line = self.rfile.readline()
if bytes_line == b"":
print("--- Client disconnected")
try:
bytes_line = self.rfile.readline()
if bytes_line == b"":
print("--- Client disconnected")
print("--- Waiting for connections")
return
except TimeoutError:
print("--- Disconnecting client because of timeout")
print("--- Waiting for connections")
return

Expand Down

0 comments on commit 57e604a

Please sign in to comment.