Skip to content

Commit

Permalink
Merge pull request #16 from mvdwetering/add_40_seconds_idle_timeout
Browse files Browse the repository at this point in the history
Add 40 seconds idle timeout like real receiver
  • Loading branch information
mvdwetering authored Mar 30, 2024
2 parents 357f30a + 57e604a commit 2e301ac
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 2e301ac

Please sign in to comment.