Server-sent events
The classic model of HTTP communication is the single-request-response model: the client issues a request to the server, the server sends a response, the connection gets closed, that's all! Each HTTP connection serves exactly one response.
In some scenarios, the opposite of this model is required—the server sends some data to the client, without a special request from the client. This is very common in notification systems, such as social media notification pop-ups, or in applications such as chatting. When the client has a new notification or a chatting message, the server should redirect it to the client.
It is technically impossible for the server to initiate a connection to the client; therefore, some techniques were invented to support this model, which we are going to summarize as follows:
- Polling: The client repeatedly requests new content from the server. For example, in a chatting application, the client will issue a request each second to check for new messages...