How to make a persistent connection
If the websocket object lost the connection to the server how we can re-connect it without affecting the application. write now it is throwing
WebSocketConnectionClosedException
I have a problem that may be the same as you, I recieve data maybe for 1 minute, and server give me a None, then go to do _socket.py if not bytes: raise WebSocketConnectionClosedException("Connection is already closed.") When go to do raise WebSocketConnectionClosedException("Connection is already closed."), I want to send something to server for keeping alive. Could I do that? right now, I send message every 30s to avoid WebSocketConnectionClosedException,is there a better way?
I have a problem that may be the same as you, I recieve data maybe for 1 minute, and server give me a None, then go to do _socket.py if not bytes: raise WebSocketConnectionClosedException("Connection is already closed.") When go to do raise WebSocketConnectionClosedException("Connection is already closed."), I want to send something to server for keeping alive. Could I do that? right now, I send message every 30s to avoid WebSocketConnectionClosedException,is there a better way?
It's amazing that I use 30s replace with 45s and then it never raise exceptions again.
If you are getting an error stating that the connection is closed, then either 1. the client closed the connection or 2. the server closed the connection.
- To keep the client listening in a long-lived connection, it is better to use the WebSocketApp class rather than the WebSocket class. Examples of both options are given in the examples documentation and in the README.md.
- If the server is closing the connection, you may be able to keep the connection alive by setting a ping interval, which will ping the server at a certain interval (for example, 30 seconds or 45 seconds) in an attempt to keep the connection alive.
For future reference, this is similar to #281.