|
|
|
|
|
by jongjong
433 days ago
|
|
I don't know why people keep trying desperately to avoid the simplicity and flexibility of WebSockets. A lot of times, what people need is a bidirectional connection yet somehow they convince themselves that SSE is better for the job... But they end up with two different types of streams; HTTP for writes and responses and SSE for passively consuming real-time data... Two different stream types with different lifecycles; one connection could fail while the other is fine... There is no way to correctly identify what is the current connection status of the app because there are multiple connections/statuses and data comes from multiple streams... Figuring out how to merge data coming from HTTP responses with data coming in passively from the SSE is messy and you have no control over the order in which the events are triggered across two different connections... You can't enforce a serial, sequential, ordered flow of data over multiple connections as easily, it gets messy. With WebSockets, you can easily assign an ID to requests and match it with a response. There are plenty of WebSocket frameworks which allow you to process messages in-order. The reason they work and are simple is because all messages pass over a single connection with a single state. Recovering from lost connections is much more straight forward. |
|
These are tools, not religions.
Websockets have some real downsides if you don't need bidirectional comms.