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.

What are Server-Sent Events?

SSE provides a simple, standardized way for servers to push data to clients over a persistent HTTP connection.

Simple Server-to-Client Streaming

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.

  • Uses standard HTTP — no special server configuration
  • Automatic reconnection with configurable retry intervals
  • Event IDs for resuming from where you left off
  • Works through proxies, firewalls, and CDNs
SERVER CLIENT text/event-stream data: {"event": "..."}

SSE Features

Simple yet powerful server-to-client push notifications.

Unidirectional Streaming

Server-to-client only — the simplest possible real-time architecture. When you only need to push data to clients, SSE is the ideal choice.

Automatic Reconnection

Built-in reconnection logic with configurable retry intervals. The client automatically reconnects when the connection drops.

Event IDs for Resume

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.

text/event-stream

Standard MIME type and simple text format. Events are plain text with optional named event types, making them easy to generate and parse.

Proxy & Firewall Friendly

Uses standard HTTP, so SSE works through corporate proxies, firewalls, and CDNs without special configuration or port opening.

WebSocket Fallback

Use SSE as a lightweight fallback in environments where WebSocket connections are blocked or restricted.

SSE Use Cases

Scenarios where unidirectional server push is all you need.

Live Feeds

Stream live news, social media updates, and content feeds to applications with real-time push delivery.

Stock Tickers

Push real-time stock prices, market data, and trading alerts to client applications with minimal latency.

Notification Systems

Deliver real-time notifications, alerts, and system messages to users without polling or manual refresh.

Log Streaming

Stream application logs, server events, and debug output in real time for monitoring and troubleshooting.

Build Status Updates

Push CI/CD pipeline status, build progress, and deployment notifications to developer dashboards in real time.

Delphi SSE Example

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;

Ready to Get Started with SSE?

Download the free trial and start receiving server-pushed events in minutes.