Closed tamir-laminar closed 1 month ago
This is essentially https://websockets.readthedocs.io/en/stable/faq/asyncio.html#why-does-my-program-never-receive-any-messages
This code doesn't actually yield control to the event loop until await client.recv()
. Only then does the event loop get a chance to run and to notice that the connection has been close.
If you add await asyncio.sleep(0.1)
right after connect()
, you should get the behavior that you expect.
There is a problem with the client
state
when sending messaged over a closed socket.look at the example below:
output:
In this example the server gets a connection request from the client and just drop the connection. The client can still sends messages without getting
ConnectionClosedOK
exception.Notes:
11.0
, in version10.4
we would get error in that case.CLOSING
, but other routine changes the state back toOPEN
although it is still close.