I don't have that much experience 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 time of inactivity (I think 1 hour or so). 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 from the server for like 2 minutes until the onclose handler of the socket I implemented fires and replaces the socket.
However, this is much too 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 ensure a working socket connection is always open? E.g. by setting an interval to call .close() on the WebSocket? Anyone experienced something similar?