Server-Sent Events (SSE)
HTTP-based server-to-client push notifications. A lightweight, reliable approach to real-time data streaming that works everywhere HTTP works.
HTTP-based server-to-client push notifications. A lightweight, reliable approach to real-time data streaming that works everywhere HTTP works.
SSE provides a simple, standardized way for servers to push data to clients over a persistent HTTP connection.
Server-Sent Events use a simple HTTP connection to stream events from server to client. Unlike WebSocket, SSE is unidirectional — the server sends data and the client receives it. This simplicity is its strength: SSE works through HTTP proxies, load balancers, and firewalls without any special configuration. The browser (or client library) handles reconnection automatically, and event IDs enable seamless resume after a disconnection. sgcWebSockets provides a complete SSE client that integrates naturally with Delphi applications.
Simple yet powerful server-to-client push notifications.
Server-to-client only — the simplest possible real-time architecture. When you only need to push data to clients, SSE is the ideal choice.
Built-in reconnection logic with configurable retry intervals. The client automatically reconnects when the connection drops.
Each event can carry an ID. After reconnection, the client sends the last event ID so the server can resume from where it left off.
Standard MIME type and simple text format. Events are plain text with optional named event types, making them easy to generate and parse.
Uses standard HTTP, so SSE works through corporate proxies, firewalls, and CDNs without special configuration or port opening.
Use SSE as a lightweight fallback in environments where WebSocket connections are blocked or restricted.
Scenarios where unidirectional server push is all you need.
Stream live news, social media updates, and content feeds to applications with real-time push delivery.
Push real-time stock prices, market data, and trading alerts to client applications with minimal latency.
Deliver real-time notifications, alerts, and system messages to users without polling or manual refresh.
Stream application logs, server events, and debug output in real time for monitoring and troubleshooting.
Push CI/CD pipeline status, build progress, and deployment notifications to developer dashboards in real time.
Connect to an SSE endpoint and receive server-pushed events.
uses
sgcSSE_Client, sgcSSE_Classes;
var
SSEClient: TsgcSSEClient;
procedure TForm1.FormCreate(Sender: TObject);
begin
SSEClient := TsgcSSEClient.Create(nil);
SSEClient.URL := 'https://api.example.com/events';
// Configure reconnection
SSEClient.Options.RetryInterval := 3000;
SSEClient.Options.AutoReconnect := True;
// Set up event handlers
SSEClient.OnSSEConnect := OnSSEConnect;
SSEClient.OnSSEEvent := OnSSEEvent;
SSEClient.OnSSEDisconnect := OnSSEDisconnect;
end;
procedure TForm1.ButtonConnectClick(Sender: TObject);
begin
SSEClient.Connect;
end;
procedure TForm1.OnSSEConnect(Sender: TObject);
begin
Memo1.Lines.Add('Connected to SSE stream');
end;
procedure TForm1.OnSSEEvent(Sender: TObject;
aEventName, aData, aLastEventId: string);
begin
// Handle incoming server-sent events
if aEventName = 'price-update' then
UpdatePrice(aData)
else if aEventName = 'notification' then
ShowNotification(aData)
else
Memo1.Lines.Add(aEventName + ': ' + aData);
end;
procedure TForm1.OnSSEDisconnect(Sender: TObject);
begin
// Auto-reconnect will handle reconnection
Memo1.Lines.Add('Disconnected. Reconnecting...');
end;