5 ms·
> sending a RequestID to the server so that you get request/response cycles isn't weird nor beyond the pale. To me the sticking point is what if the "response"
by hntrl 1y ago
> sending a RequestID to the server so that you get request/response cycles isn't weird nor beyond the pale.
To me the sticking point is what if the "response" message never comes? There's nothing in the websocket protocol that dictates that messages need to be acknowledged. With request/response the client knows how to handle that case natively
> And the websocket browser API is nicer to work with than, say, EventSource.
What in particular would you say?
- hombre_fatal 1y agoYeah, you'd need a lib or roll your own that races the response against a timeout. Kind of like how you also need to implement app-layer ping/pong over websockets for keepalive even though tcp already sends its own ping/pong. -_- As for EventSource, I don't remember exactly, something always comes up. That said, you could say the same for websockets since even implementing non-buggy reconn/backaway logic is annoying. I'll admit, time for me to try the thing you pitch in the article.
- throwaway2037 1y agoI have only small experience programming with web sockets, but I thought the ping pong mechanism is already built into the protocol. Does it have timeout? Does it help at the application layer? Ref: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#pings_and_pongs_the_heartbeat_of_websockets https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_...
- copperroof 1y agoYou only need to implement it yourself if you’ve catastrophically fucked up the concurrency model on the client or sever side and they can’t respond out of band of whatever you’re waiting on.
- koakuma-chan 1y agoDiscord implements its own heartbeat mechanism. I've heard websocket-native ping is somehow unreliable. Maybe in case the websocket connection is fine but something happened at the application layer?
- jand 1y ago"Unreliable" is a bit harsh - the problem arises imho not from the websocket ping itself, but from the fact that client-side _and_ server-side need to support the ping/pong frames.
- apitman 1y agoThe WebSocket browser APIs don't support ping/pong
- rodorgas 1y agoNative EventSource doesn’t let you set headers ([issue](https://github.com/whatwg/html/issues/2177 https://github.com/whatwg/html/issues/2177)), so it’s harder to handle authentication.