Middle+
Are you familiar with SSE (Server-Sent Events)?
sobes.tech AI
Answer from AI
Server-Sent Events (SSE) is a technology that allows a server to send updates to a client in real-time over a unidirectional HTTP connection. The client opens a connection and listens for events sent by the server as they occur.
SSE is convenient for applications that need to receive streaming updates, such as news, notifications, sensor data.
Example of usage on the client side (JavaScript):
const eventSource = new EventSource('/events');
eventSource.onmessage = function(event) {
console.log('New message from server:', event.data);
};
eventSource.onerror = function(err) {
console.error('SSE error:', err);
};
Advantages of SSE:
- Easy to use
- Automatic reconnection
- Text data format
Limitations:
- Unidirectional connection (server → client)
- Works only over HTTP/HTTPS
- Not supported in some older browsers
Unlike WebSocket, SSE is simpler for streaming updates without the need for two-way communication.