I don't have that much expirience with websockets yet so I wanted to ask a more general question about what is the best way to maintain a stable connection.
Basically I use a websocket client in my application to connect to a remote server that will kill idle connections after some some time of inactivity (I think 1 hour or so). In order to keep the connection alive I started implementing the onerror and onclose handler functions for the websocket to reconnect if that happens. That works great for certain errors, but I noticed that sometimes after a long period of inactivity it seems like the connection is still open and I am able to send messages to the socket but I don't receive a response by the server for like 2 minutes until the onclose handler of the socket I implemented fires and replaces the socket.
However this is much to late for my use cases. What's the best way to deal with it? Is it good practice to periodically close and replace the connection on my end to make sure there is always a working socket connection open? E.g. by setting an interval to call .close() on the websocket? Anyone expirienced something similar?
from Websocket Client Reconnect Idle Connection
No comments:
Post a Comment