Delphi WebSocket Component — Production-Grade Client & Server

A native, RFC 6455 WebSocket implementation for Delphi and C++Builder. Build clients and servers that hold thousands of concurrent connections, run on Windows, macOS, Linux, iOS and Android, and survive flaky networks with the built-in WatchDog auto-reconnect.

What is a Delphi WebSocket component?

A drop-in VCL/FMX component that turns the WebSocket protocol into a property-and-event API native Delphi developers recognise.

A Delphi WebSocket component is a non-visual component you drop on a form (or instantiate at runtime) to open a full-duplex TCP channel between a Delphi application and any RFC 6455 WebSocket peer — a browser, a Node.js service, an nginx reverse proxy, a Mosquitto broker, an OpenAI Realtime endpoint or another Delphi process. Unlike polling HTTP, a WebSocket keeps the connection open: the server can push data the moment it is available, with millisecond latency and no per-message HTTP overhead.

sgcWebSockets has been the reference WebSocket library in the Delphi ecosystem since 2013. The same TsgcWebSocketClient and TsgcWebSocketHTTPServer components run unchanged on Delphi 7 through Delphi 13, on Win32, Win64, Linux64, macOS, iOS and Android, and on C++Builder C2007 through C13. There is no managed runtime, no .NET interop layer, no JavaScript bridge — it is a pure Pascal implementation that compiles into your binary.

Component class

TsgcWebSocketClient / TsgcWebSocketHTTPServer

Standards

RFC 6455, RFC 7692 (permessage-deflate)

Platforms

Windows, macOS, Linux, iOS, Android

Delphi versions

Delphi 7 → Delphi 13 + C++Builder

Why pick sgcWebSockets over rolling your own

Writing one PING/PONG handler is easy. Surviving a TLS-terminating reverse proxy, an IIS WebSocket module, a corporate firewall, a mobile cellular handover and a 5,000-client load test is not.

One API, every transport

Plain WebSocket (ws://), TLS WebSocket (wss://), WebSocket over HTTP/2, WebSocket over QUIC/HTTP/3, raw TCP fallback — same component, same events. Switch transport by changing one property.

WatchDog auto-reconnect

Enable WatchDog and the client will reconnect with exponential back-off, re-authenticate, re-subscribe to MQTT topics and replay any queued publications — the canonical mobile / IoT pattern, already written.

Threading is solved

The server uses an IOCP / kqueue / epoll reactor under the hood. You write event handlers; the library schedules them across a thread pool with per-connection serialisation.

permessage-deflate

Negotiated automatically per RFC 7692. Cuts JSON payloads by 70–90 % and is supported by every modern browser and load balancer.

Sub-protocols included

MQTT 3.1.1/5.0, AMQP 0.9.1/1.0, STOMP, WAMP and Server-Sent Events ride on top of the same WebSocket transport — one TCP socket, multiple application protocols.

HTTP server, too

TsgcWebSocketHTTPServer serves static files, REST endpoints, JWT- and OAuth2-protected resources, gzip-compressed responses and HTTP/2 upgrade in the same process as your WebSocket endpoint.

TLS that actually works

OpenSSL (cross-platform), SChannel (Windows kernel TLS) or HTTP.sys. Client certificates, SNI, ALPN, TLS 1.3 with 0-RTT.

Channels & broadcast

Server-side Channels group connections by name. Broadcast, BroadcastByChannel and BroadcastByUser fan out to thousands of peers in a single call.

Battle-tested

In production at banks, exchanges, IoT fleets and trading firms since 2013. Updated every month; history.txt tracks every fix.

Feature checklist

Everything the RFC says, plus the operational hardening real deployments need.

CapabilityClientServer
RFC 6455 framing (text, binary, ping, pong, close)YesYes
permessage-deflate (RFC 7692)YesYes
Fragmented & continuation framesYesYes
Masked client messagesYesn/a
TLS 1.2 / 1.3 (OpenSSL + SChannel)YesYes
Client certificates / mTLSYesYes
JWT & OAuth2 authenticationYesYes
HTTP/2 + WebSocket (RFC 8441)YesYes
HTTP/3 + WebSocket over QUIC (RFC 9220)YesYes
WatchDog auto-reconnectYesn/a
Heart-beat (PING/PONG)YesYes
Channels & broadcastn/aYes
Sub-protocols (MQTT / AMQP / STOMP / WAMP / SSE)YesYes
HTTP.sys hosting (Windows kernel)n/aYes
Linux daemon modeYesYes

Hello WebSocket — Delphi client in 12 lines

Drop a TsgcWebSocketClient on the form, set Host / Port, handle OnMessage, set Active := True.

uses
  sgcWebSocket, sgcWebSocket_Classes;

procedure TForm1.FormCreate(Sender: TObject);
begin
  WS := TsgcWebSocketClient.Create(nil);
  WS.URL := 'wss://echo.websocket.events';
  WS.WatchDog.Enabled := True;
  WS.WatchDog.Interval := 5;
  WS.OnConnect := WSConnect;
  WS.OnMessage := WSMessage;
  WS.OnDisconnect := WSDisconnect;
  WS.Active := True;
end;

procedure TForm1.WSMessage(Connection: TsgcWSConnection; const Text: string);
begin
  Memo1.Lines.Add('<< ' + Text);
end;

procedure TForm1.ButtonSendClick(Sender: TObject);
begin
  WS.WriteData('{"hello":"world"}');
end;

Server side is symmetric — drop a TsgcWebSocketHTTPServer, set Port, handle OnConnect and OnMessage, call Broadcast to fan out to every connected peer.

Supported Delphi & C++Builder versions

One source tree, 22 runtime packages — covering every Delphi release still in active commercial use.

EditionVersions
Delphi / RAD Studio7, 2007, 2009, 2010, XE, XE2, XE3, XE4, XE5, XE6, XE7, XE8, 10 Seattle, 10.1 Berlin, 10.2 Tokyo, 10.3 Rio, 10.4 Sydney, 11 Alexandria, 12 Athens, 13
C++Builder2007, 2009, 2010, XE, XE2, XE3, XE4, XE5, XE6, XE7, XE8, 10, 10.1, 10.2, 10.3, 10.4, 11, 12, 13
FreePascal / Lazarus3.x (via sgcIndy base)
PlatformsWin32, Win64, Linux64, macOS Intel/ARM, iOS device + simulator, Android ARM/ARM64

Keep exploring

The WebSocket transport is the foundation of every other protocol in the library.

What are WebSockets?

Background on the RFC 6455 protocol, the handshake, framing and use cases.

MQTT sub-protocol

Run MQTT 3.1.1 / 5.0 over the same WebSocket connection.

HTTP/2 client & server

Multiplexed HTTP/2 with server push and WebSocket-over-HTTP/2.

Real-time protocol picker

WebSocket vs SSE vs HTTP/2 push vs MQTT vs WebRTC — decision matrix.

Blog: Channels, groups & users

Pattern guide for broadcasting to subsets of connections.

Blog: WatchDog & BeforeConnect

How the auto-reconnect lifecycle works under the hood.

Blog: Faster compression

Tuning permessage-deflate for throughput vs CPU.

Frequently asked questions

Which Delphi versions are supported?

Every commercial Delphi release from Delphi 7 (2002) through Delphi 13 (2025), plus matching C++Builder versions. We ship 22 separate runtime packages — one per IDE — from a single source tree. There is no separate “legacy” SKU; every customer gets every version.

Does the WebSocket component support TLS / wss://?

Yes. Set URL := 'wss://...' and pick a TLS provider: OpenSSL (cross-platform, ships with the trial), SChannel (Windows kernel TLS, no DLLs to deploy), or HTTP.sys (server-side, certificate stored in the Windows certificate store). Client certificates, SNI, ALPN, TLS 1.3 and 0-RTT are all supported.

How many concurrent connections can the server handle?

On Windows the server uses IOCP and routinely scales to 50,000+ concurrent connections per process on commodity hardware. On Linux the epoll reactor scales similarly. The hard limit is OS-level (file descriptors, ephemeral port range, kernel memory), not the library.

What is the licensing model?

Royalty-free per-developer perpetual licence with one year of updates included. Single-developer, team and site licences available — see pricing. Source code is included with every commercial edition.

Ready to add WebSockets to your Delphi app?

Download the fully-functional 30-day trial — client, server, all sub-protocols, all Delphi versions.