r/programming • • Jun 13 '19

WebSockets vs Long Polling

https://www.ably.io/blog/websockets-vs-long-polling/
581 Upvotes

199 comments sorted by

View all comments

Show parent comments

16

u/hashtagframework Jun 13 '19

What about clients using VPNs or behind restrictive firewalls? I was more concerned about the network limitations. Does the WebSocket tunnel just like a normal TCP keep-alive HTTP request? Are they prone to disconnects?

4

u/sephg Jun 13 '19

Yes and yes. But you need a strategy / code for reconnecting anyway so it’s not that big a deal. Arguably long polling is similar to websockets except where you reconnect after every message that is sent to the client.

2

u/hashtagframework Jun 13 '19

Thanks, that's how I understood it. I usually implement long polling to stream messages and keep the connection alive as long as possible... I usually set it 5-10 seconds under the max execution time for front-end requests.

5

u/sephg Jun 13 '19

That sounds like a hand-rolled version of server sent events. I'd recommend just using SSE directly. SSE is which are supported already by almost all browsers. (All browsers when using a polyfill.)

→ More replies (0)