How to decide the Ping interval for websocket connection
Asked Answered
H

3

32

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

Hypoacidity answered 29/1, 2013 at 5:33 Comment(0)
X
21

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".

Xerxes answered 11/8, 2014 at 4:30 Comment(0)
C
8

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.

Canale answered 29/1, 2013 at 9:0 Comment(0)
E
1

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.

Edh answered 2/9, 2023 at 13:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.