Delphi WebSocket Server

TsgcWebSocketHTTPServer — a multithreaded WebSocket and HTTP server component with IOCP/EPOLL support, SSL/TLS, authentication, and static file serving.

TsgcWebSocketHTTPServer

HTTP + WebSocket server — serves wss:// handshakes, broadcasts messages, and ships with built-in TLS, authentication, load-balancer registration and HTTP/2.

Component class

TsgcWebSocketHTTPServer

Protocol

WebSocket — RFC 6455

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Professional / Enterprise

Drop the component, set a few properties, go

Drop a TsgcWebSocketHTTPServer, set Port and SSL, wire OnMessage and the server is live.

uses
  sgcWebSocket, sgcWebSocket_Server, sgcWebSocket_Classes;

var
  WSServer: TsgcWebSocketHTTPServer;
begin
  WSServer := TsgcWebSocketHTTPServer.Create(nil);
  WSServer.Port := 80;

  WSServer.OnConnect       := WSServerConnect;
  WSServer.OnMessage       := WSServerMessage;
  WSServer.OnDisconnect    := WSServerDisconnect;
  WSServer.OnError         := WSServerError;
  WSServer.OnAuthentication := WSServerAuthentication;

  WSServer.Active := True;
end;

procedure TForm1.WSServerMessage(Connection: TsgcWSConnection;
  const Text: string);
begin
  // Broadcast to every connected client
  WSServer.WriteData(Text);
end;

procedure TForm1.WSServerAuthentication(Connection: TsgcWSConnection;
  aUser, aPassword: string; var Authenticated: Boolean);
begin
  Authenticated := (aUser = 'admin') and (aPassword = 's3cret');
end;
// uses: sgcWebSocket, sgcWebSocket_Server
TsgcWebSocketHTTPServer *WSServer = new TsgcWebSocketHTTPServer(this);
WSServer->Port = 80;

WSServer->OnConnect       = WSServerConnect;
WSServer->OnMessage       = WSServerMessage;
WSServer->OnDisconnect    = WSServerDisconnect;
WSServer->OnError         = WSServerError;
WSServer->OnAuthentication = WSServerAuthentication;

WSServer->Active = true;

void __fastcall TForm1::WSServerMessage(TsgcWSConnection *Connection,
    const UnicodeString Text)
{
  WSServer->WriteData(Text);
}
using esegece.sgcWebSockets;

var server = new TsgcWebSocketHTTPServer();
server.Port = 80;

server.OnConnect        += (conn) => Console.WriteLine("#connected: " + conn.IP);
server.OnMessage        += (conn, text) => server.WriteData(text);  // broadcast
server.OnDisconnect     += (conn, code) => Console.WriteLine("#disconnected: " + code);
server.OnAuthentication += (conn, user, pass, ref ok) => { ok = (user == "admin" && pass == "s3cret"); };

server.Active = true;

What's inside

27 published properties, 7 methods, 22 events — pulled from the component reference.

Connection

Published properties: Active, Port, Bindings.

Messaging

Methods: Broadcast, WriteData, Ping.

Reliability

Published properties: HeartBeat, WatchDog, LoadBalancer.

Security

Published properties: Authentication, SSL, SSLOptions.

Lifecycle

Events: OnStartup, OnShutdown, OnTCPConnect.

Data

Events: OnMessage, OnBinary, OnFragmented.

Specifications & references

Authoritative sources for the protocols this component implements.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Online Help — TsgcWebSocketServer Full property, method and event reference for this component.
Demo Project — 01.WebSocket\02.Server Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi, C++ Builder and .NET and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Ready to Build Your Server?

Download the free trial and create a high-performance WebSocket server in minutes.