Skip to content

Commit

Permalink
Handle handshake with slow clients such as microcontrollers
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Aug 24, 2022
1 parent e174491 commit 271f8fc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/simple_websocket/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,15 @@ def handshake(self):
subprotocols=self.subprotocols or []))
self.sock.send(out_data)

in_data = self.sock.recv(self.receive_bytes)
self.ws.receive_data(in_data)
event = next(self.ws.events())
while True:
in_data = self.sock.recv(self.receive_bytes)
self.ws.receive_data(in_data)
try:
event = next(self.ws.events())
except StopIteration: # pragma: no cover
pass
else: # pragma: no cover
break
if isinstance(event, RejectConnection): # pragma: no cover
raise ConnectionError(event.status_code)
elif not isinstance(event, AcceptConnection): # pragma: no cover
Expand Down

0 comments on commit 271f8fc

Please sign in to comment.