Skip to content

Commit

Permalink
Add delay in initial connection
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasyoder committed Sep 14, 2024
1 parent 1c76f14 commit 70bb3df
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def handle(self):
if self.request not in SOCKETS:
SOCKETS.append(self.request)
info_notify(f'New connection from {self.request}')
sleep(0.1) # small delay to allow client to initialize

new_caps = {}
for dev in KM_DEVS:
Expand Down Expand Up @@ -132,9 +133,9 @@ def handle_events(self, device):
sock = SOCKETS[self.socket_index]
try:
sock.send(bytes(f"{json.dumps(data)}\n", "utf-8"))
except OSError:
except (OSError, BrokenPipeError):
warning_notify(f'Dropped connection: {sock}')
del SOCKETS[self.socket_index]
SOCKETS.remove(sock)
self.socket_index = -1
self.grabbing = False
device.close()
Expand Down

0 comments on commit 70bb3df

Please sign in to comment.