When the connection is lost, the socket will be closed and the WebSocketSubjet will no longer emit values. This is not the expected behaviour in the real time world. The reconnection capability is a must in most cases.
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1000 (OK), no reason Also app.py code: #!/usr/bin/env python3.6 import asyncio from server import Server if __name__ == '__main__': ws = Server() asyncio.get_event_loop().run_until_complete(ws.start()) asyncio.get_event_loop().run_forever()
If you still know the WebSocket handle of the connection, you can still display the trace. For this, select WebSocket Trace Display while another connection is selected. In the popup window enter the WebSocket handle of your closed connection under “WebSocket” and confirm.
This code works well on iOS 13. The Xcode that I uses is Version 12.0 beta 2 (12A6163b) But the websocket is disconnected automatically (with the close code of NSURLSessionWebSocketCloseCodeProtocolError = 1002) a few seconds after the connection is created on iOS 14 beta2. If I send short messages (e.g the message length < 10), iOS 14 beta2 might have much better chance to keep the websocket connection.
I also tried to comment out the one and only part of my code that seemed to have anything to do with closing the connection. I'm not sure where I'm messing it up. This is all the websocket code I have in the frontend (also with extra backend context if needed):
A wss prefix identifies the WebSocket Secure connection Streaming Connection – indicates whether the TCP session will remain. If checked – the connection will persist, if left unchecked – the connection will be closed after the first response Request Data – defines outgoing messages
Events that are fired when a websocket event occurs (when a socket is opened, closed, or receives an error response) A simple implementation of a WebSocket connection may look as follows: Once the WebSocket constructor is called, the browser and server initiate a handshake.