Server-sent events
lastmod 2024-12-30created 2019-07-159 edits
Traditionally, a web page has to send a request to the server to receive new data; that is, it requests data from the server. With Server-Sent Events, however, the server can send new data at any time without a request from the web page. Messages sent this way can be handled inside the web page as Events + data.
How it works
Flowchart_of_SSE.jpg
Using Server-Sent Events instead of WebSockets
When building a real-time web application, WebSockets usually come to mind, but SSE can also be a simple alternative
- Problems with WebSockets: not based on HTTP, so they miss out on HTTP's benefits
- No compression, poor HTTP/2 multiplexing support, not supported by proxies, hijacking possible
- Lets the server send Low-Latency push events to the client
- An HTML standard supported by all browsers (except IE)
- Unlike WebSockets, SSE flows in one direction, from server to client (not suitable for games that need bidirectional communication)
- Runs over HTTP and needs no separate protocol
See also
- Server-sent events (SSE)
- Event stream format
- Push technology
- Akka:Http:SSE (how to implement SSE in akka-http)
- Mercure - an open protocol based on SSE