Delphi WebSocket Server
TsgcWebSocketHTTPServer — a multithreaded WebSocket and HTTP server component with IOCP/EPOLL support, SSL/TLS, authentication, and static file serving.
TsgcWebSocketHTTPServer — a multithreaded WebSocket and HTTP server component with IOCP/EPOLL support, SSL/TLS, authentication, and static file serving.
HTTP + WebSocket server — serves wss:// handshakes, broadcasts messages, and ships with built-in TLS, authentication, load-balancer registration and HTTP/2.
TsgcWebSocketHTTPServer
WebSocket — RFC 6455
Windows, macOS, Linux, iOS, Android
Professional / Enterprise
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;
27 published properties, 7 methods, 22 events — pulled from the component reference.
Published properties: Active, Port, Bindings.
Methods: Broadcast, WriteData, Ping.
Published properties: HeartBeat, WatchDog, LoadBalancer.
Published properties: Authentication, SSL, SSLOptions.
Events: OnStartup, OnShutdown, OnTCPConnect.
Events: OnMessage, OnBinary, OnFragmented.
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. | Open | |
| Demo Project — 01.WebSocket\02.Server Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below. | Open | |
| Technical Document (PDF) Features, quick start, code samples for Delphi, C++ Builder and .NET and primary-source references — this component only. | Open | |
| User Manual (PDF) Comprehensive manual covering every component in the library. | Open |