I understand the Ping is to help prevent proxies from closing idle connections. Is there any guidelines w.r.t. how often to ping? Once every second? 10 seconds? Minute? Does it even matter? A preliminary google search gives me nothing, and the websocket spec only says what a ping is, not how often you should do it
I know this is an old question, but i've also been in search for an answer. The previous answer does not make mention of the interval, so I searched through some code of some popular websocket frameworks. Not that this is official, but at least it gives a starting point: this repo makes use of 20 second intervals. I'm not sure if that 100% correct, but its better than "often", or "somewhat frequently".
The accepted answer to the following SO thread seems to answer your question pretty well:
Sending websocket ping/pong frame from browser
It sounds like you can ping fairly often (using your own custom ping/pong strings), and unless there are a ton of clients connected to your WebSocket server, then the load on the system will be fairly minimal.
in my practice something around 55seconds usually ensures reliable connections, as most intermediate proxies and NAT routers have their timeout set to at least 60s.
Note however, that a given server may set much lower idle timeout on it's side depending on a given app's specifics.
© 2022 - 2024 — McMap. All rights reserved.