What are Server-Sent Events (SSE)?
While protocols like WebSockets and HTTP Long Polling provide bi-directional connectivity between clients and servers, ideal for many applications such as in-app chat and multiplayer gaming, in some cases, you don't need to communicate both ways. Two-way (bidirectional) communication isn't necessary. Sometimes clients simply need to fetch data from servers (for example, news feeds, stock market prices, sports scores).
This is where Server-Sent Events (SSE) programming is optimal. SSE is part of HTML5 specification and is primarily used to engage servers with server-push notifications. It is known as simple programming that utilizes HTTP protocols to gather and retrieve data. SSE, also known as “Event Source,” typically deals with the content type Text/Event-Stream, which basically initiates SSE to begin working on a webpage.
When SSE is initiated by the client, it:
- Opens a one-way, continuous connection from server to client where new data is retrieved and delivered to the client on an arbitrary basis.
- Continues sending new data or information until such a time that the client no longer needs to connect to the webpage and decides to terminate the connection by closing the program or webpage.