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?
Anything that terminates SSL and breaks websockets breaks a significant portion of the modern web. This is really only a concern if you are forced to support extremely enterprise, extremely backwards clients. The only modern application that doesn't really handle this is IoT, where you should probably be using something like MQTT instead.
I have encountered networks that sever long running TCP connections though. On a college campus near me, the school network causes my SSH sessions to get disconnected after a certain period of time, like 15 minutes. I think it is trying to preserve router ports or something because common space networks could have hundreds of devices on them, and tens of thousands of TCP connections. I don't know that is the actual reason but I do know it is intentionally cutting off long-running connections.
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.
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.
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.)
Arguably long polling is similar to websockets except where you reconnect after every message that is sent to the client.
Re-establishing the TCP connection each message will be inefficient. Long-polling systems should maintain the TCP connection while sending/receiving messages. Long-polling systems should leverage the subsequent subscription requests as message receive receipts to acknowledge the receipt of a message. Long-polling systems should use HTTP/2.0 for full duplex support with one TCP connection.
Lots of older security proxy solutions don’t work well with web sockets. Nginx handles it fairly well, but older versions of ISAM does not at all. Just passes the upgrade request along, but closes it so you can’t reply.
Using a library like socket.io enables you to leverage web sockets even when dealing with clients or proxies that can’t, but yes, you’ll end up actually using long polling, but at least you don’t need to implement it.
Do you use read receipts to confirm messages are received? Is that built into websockets? When the websocket reconnects, so you need to flush the entire state, or how do you deal with lost messages?
425
u/[deleted] Jun 13 '19
[removed] — view removed comment