High-Performance Async WebSocket Components for Delphi
See the components in action with real-time WebSocket connections, bulletproof encryption, and enterprise-grade performance!
- mORMot2's WebSocket Framework: Leverages the lightning-fast mORMot2 async WebSocket architecture
- Thousands of Concurrent Connections: Handle massive WebSocket client loads with ease
- Standard WebSocket Protocol: Full RFC 6455 compliance with frame-based communication
- Real-Time Bidirectional: Instant push/pull communication between client and server
- Drop-in Components: Familiar Delphi component architecture with events and properties
- Thread-Safe Design: Bulletproof multi-threaded WebSocket operation
- Smart Auto-Reconnection: Intelligent reconnection strategies with exponential backoff
- Coordinated Encryption: Advanced AES encryption with automatic parameter coordination
- AES Encryption: Full AES support with automatic mode/key coordination (ECB, CBC, CFB, OFB, CTR, GCM, CFC, OFC, CTC)
- Connection State Management: Advanced state tracking and statistics
- Robust Error Handling: Comprehensive error propagation and recovery
- Professional Logging: Configurable logging levels for debugging and monitoring
-
Build the Package
Open mORMot2WebSocketComponents.dproj β Build β Install
-
Add Library Path
Tools β Options β Library Path β Add source folder path
-
Start Building!
Find components in Tool Palette under "mORMot2 WebSocket"
The powerhouse WebSocket server component that accepts and manages multiple simultaneous WebSocket connections with enterprise-grade performance.
Property | Type | Default | Description |
---|---|---|---|
Active |
Boolean | False | β‘ Start/stop the WebSocket server |
Port |
Integer | 8080 | π Server listening port |
MaxConnections |
Integer | 1000 | π₯ Maximum concurrent connections |
ServerThreadPoolCount |
Integer | 32 | π§΅ Async thread pool size |
KeepAliveTimeOut |
Integer | 30000 | β±οΈ Keep-alive timeout (ms) |
WebSocketsURI |
String | "websocket" | π WebSocket endpoint URI |
WebSocketsAjax |
Boolean | True | π‘ Enable AJAX fallback |
EncryptionEnabled |
Boolean | False | π Enable AES encryption |
EncryptionKey |
String | "" | π AES encryption key |
EncryptionMode |
TAESMode | amCBC | π‘οΈ AES encryption mode |
EncryptionKeySize |
TAESKeySize | aks256 | π Key size (128/192/256) |
Property | Type | Description |
---|---|---|
ClientCount |
Integer | π₯ Current active connections |
TotalConnections |
Int64 | π Total connections since start |
TotalActiveConnections |
Int64 | π΄ Live connection count |
TotalBytesReceived |
Int64 | π₯ Total bytes received |
TotalBytesSent |
Int64 | π€ Total bytes sent |
TotalMessagesReceived |
Int64 | π¨ Total messages received |
TotalMessagesSent |
Int64 | π€ Total messages sent |
Event | Description |
---|---|
OnClientConnected |
π WebSocket client connected |
OnClientDisconnected |
π WebSocket client disconnected |
OnDataReceived |
π¨ Process incoming WebSocket data |
OnDataSent |
π€ WebSocket data transmission complete |
OnHandleCommand |
π Handle WebSocket commands |
OnError |
β Error occurred |
OnServerStateChange |
π Server state changed |
The intelligent WebSocket client component with bulletproof auto-reconnection and smart connection strategies.
Property | Type | Default | Description |
---|---|---|---|
Active |
Boolean | False | β‘ Connect/disconnect |
Host |
String | "localhost" | π Server hostname/IP |
Port |
Integer | 80 | π Server port |
URI |
String | "/" | π WebSocket URI path |
Connected |
Boolean | False | π Connection state |
ConnectionTimeout |
Integer | 30000 | β±οΈ Connection timeout (ms) |
AutoReconnect |
Boolean | False | π Enable auto-reconnection |
ReconnectStrategy |
TWebSocketReconnectStrategy | rsLinear | π Reconnection strategy |
ReconnectInterval |
Integer | 5000 | β° Base reconnection interval (ms) |
MaxReconnectAttempts |
Integer | 0 | π’ Maximum reconnection attempts |
Strategy | Description |
---|---|
rsLinear |
β° Fixed interval reconnection |
rsExponential |
π Exponential backoff (smart) |
Property | Type | Description |
---|---|---|
ConnectionState |
TWebSocketConnectionState | π Current connection state |
ConnectionStateDescription |
String | π Human-readable state |
TotalBytesReceived |
Int64 | π₯ Total bytes received |
TotalBytesSent |
Int64 | π€ Total bytes sent |
Reconnecting |
Boolean | π Currently reconnecting |
Event | Description |
---|---|
OnConnect |
π Connected to WebSocket server |
OnDisconnect |
π Disconnected from server |
OnDataReceived |
π¨ Process incoming WebSocket data |
OnDataSent |
π€ WebSocket data sent |
OnHandleCommand |
π Handle WebSocket commands |
OnError |
β Error occurred |
OnStateChange |
π Connection state changed |
OnReconnecting |
π Attempting reconnection |
OnReconnectFailed |
β Reconnection attempt failed |
// Start server
procedure TServerForm.StartServer;
begin
mORMot2WebSocketServer1.Port := 8080;
mORMot2WebSocketServer1.Active := True;
end;
// Stop server
procedure TServerForm.StopServer;
begin
mORMot2WebSocketServer1.Active := False;
end;
// Connect to server
procedure TClientForm.ConnectToServer;
begin
mORMot2WebSocketClient1.Host := '127.0.0.1';
mORMot2WebSocketClient1.Port := 8080;
mORMot2WebSocketClient1.Connect;
end;
// Disconnect from server
procedure TClientForm.DisconnectFromServer;
begin
mORMot2WebSocketClient1.Disconnect;
end;
// Send to specific client
procedure TServerForm.SendToClient(ClientID: Integer);
var
Data: TBytes;
begin
Data := BytesOf('Hello Client!');
mORMot2WebSocketServer1.SendCommandToClient(ClientID, Data);
end;
// Send to server
procedure TClientForm.SendToServer;
var
Data: TBytes;
begin
Data := BytesOf('Hello Server!');
mORMot2WebSocketClient1.SendCommand(Data);
end;
// Broadcast message to all connected clients
procedure TServerForm.BroadcastToAll;
var
Data: TBytes;
begin
Data := BytesOf('Message for everyone!');
mORMot2WebSocketServer1.BroadcastCommand(Data);
end;
// Get client information (implement via tracking)
procedure TServerForm.ShowAllClients;
begin
// Total client count
ShowMessage(Format('Total clients: %d', [mORMot2WebSocketServer1.GetClientCount]));
// Client IP example
ShowMessage(mORMot2WebSocketServer1.GetClientIP(ClientID));
end;
// Configure server encryption
procedure TServerForm.SetupEncryption;
begin
mORMot2WebSocketServer1.EncryptionEnabled := True;
mORMot2WebSocketServer1.EncryptionKey := 'MySecretKey123!';
// Set encryption mode (fully qualified)
mORMot2WebSocketServer1.EncryptionMode := mormot2.WebSocket.Server.TAESMode(amCBC);
// Set key size (fully qualified)
mORMot2WebSocketServer1.EncryptionKeySize := mormot2.WebSocket.Server.TAESKeySize(aks256);
end;
// Configure client encryption (must match server)
procedure TClientForm.SetupEncryption;
begin
mORMot2WebSocketClient1.EncryptionEnabled := True;
mORMot2WebSocketClient1.EncryptionKey := 'MySecretKey123!';
// Set encryption mode (fully qualified)
mORMot2WebSocketClient1.EncryptionMode := mormot2.WebSocket.Client.TAESMode(amCBC);
// Set key size (fully qualified)
mORMot2WebSocketClient1.EncryptionKeySize := mormot2.WebSocket.Client.TAESKeySize(aks256);
end;
// Different encryption modes (Server)
mORMot2WebSocketServer1.EncryptionMode := mormot2.WebSocket.Server.TAESMode(amCBC); // Default
mORMot2WebSocketServer1.EncryptionMode := mormot2.WebSocket.Server.TAESMode(amCFB); // Stream
mORMot2WebSocketServer1.EncryptionMode := mormot2.WebSocket.Server.TAESMode(amGCM); // Authenticated
// Different key sizes (Server)
mORMot2WebSocketServer1.EncryptionKeySize := mormot2.WebSocket.Server.TAESKeySize(aks128); // 128-bit
mORMot2WebSocketServer1.EncryptionKeySize := mormot2.WebSocket.Server.TAESKeySize(aks192); // 192-bit
mORMot2WebSocketServer1.EncryptionKeySize := mormot2.WebSocket.Server.TAESKeySize(aks256); // 256-bit
// Handle client connections
procedure TServerForm.mORMot2WebSocketServer1ClientConnected(Sender: TObject;
ClientID: Integer);
begin
ShowMessage(Format('Client %d connected', [ClientID]));
end;
// Handle incoming data
procedure TServerForm.mORMot2WebSocketServer1DataReceived(Sender: TObject;
ClientID: Integer; const Data: TBytes);
var
Message: string;
begin
Message := StringOf(Data);
ShowMessage(Format('Received from client %d: %s', [ClientID, Message]));
end;
// Handle connection
procedure TClientForm.mORMot2WebSocketClient1Connect(Sender: TObject);
begin
ShowMessage('Connected to server!');
end;
// Handle incoming data
procedure TClientForm.mORMot2WebSocketClient1DataReceived(Sender: TObject;
const Data: TBytes);
var
Message: string;
begin
Message := StringOf(Data);
ShowMessage('Received: ' + Message);
end;
+----------------+----------------+---------------+------------------+
| Magic (4 bytes)| Mode (4 bytes) | KeySize (4) | Reserved (4) |
+----------------+----------------+---------------+------------------+
| 0x4D4F524D | AES Mode | AES Key Size | Future Use |
+----------------+----------------+---------------+------------------+
| Encrypted WebSocket Data |
+------------------------------------------------------------------+
Mode | Description | Use Case |
---|---|---|
amECB |
Electronic Codebook | Simple, fast |
amCBC |
Cipher Block Chaining | Default, secure |
amCFB |
Cipher Feedback | Stream-like |
amOFB |
Output Feedback | Stream cipher |
amCTR |
Counter Mode | Parallel processing |
amGCM |
Galois/Counter Mode | Authenticated encryption |
amCFC |
CFC Mode | Advanced |
amOFC |
OFC Mode | Advanced |
amCTC |
CTC Mode | Advanced |
unit WebSocketServerForm;
interface
uses
System.Classes, Vcl.Forms, Vcl.StdCtrls,
mORMot2.WebSocket.Server;
type
TForm1 = class(TForm)
mORMot2WebSocketServer1: TmORMot2WebSocketServer;
ButtonStart: TButton;
ButtonStop: TButton;
Memo1: TMemo;
procedure ButtonStartClick(Sender: TObject);
procedure ButtonStopClick(Sender: TObject);
procedure mORMot2WebSocketServer1DataReceived(Sender: TObject;
ClientID: Integer; const Data: TBytes);
end;
implementation
procedure TForm1.ButtonStartClick(Sender: TObject);
begin
mORMot2WebSocketServer1.Port := 8080;
mORMot2WebSocketServer1.Active := True;
Memo1.Lines.Add('Server started');
end;
procedure TForm1.ButtonStopClick(Sender: TObject);
begin
mORMot2WebSocketServer1.Active := False;
Memo1.Lines.Add('Server stopped');
end;
procedure TForm1.mORMot2WebSocketServer1DataReceived(Sender: TObject;
ClientID: Integer; const Data: TBytes);
var
Message: string;
Response: TBytes;
begin
Message := StringOf(Data);
Response := BytesOf('Echo: ' + Message);
mORMot2WebSocketServer1.SendCommandToClient(ClientID, Response);
end;
end.
- Concurrent Connections: 1000+ simultaneous WebSocket clients
- Real-Time Communication: Ultra-low latency WebSocket frames
- Memory Usage: Efficient memory management with async connection pooling
- CPU Usage: Multi-threaded async WebSocket architecture for maximum performance
- Delphi Versions: 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, 12.2
- Platforms: Windows 32-bit & 64-bit
- Frameworks: VCL, Console applications
- Dependencies: mORMot2 framework (included)
- β mORMot2 framework properly installed
- β Windows platform (32/64-bit)
- β Delphi XE2 or later
- Coordinated Encryption: Revolutionary encryption parameter coordination between client/server
- Smart State Management: Comprehensive WebSocket connection state tracking
- Bulletproof Reconnection: Exponential backoff strategies for network interruptions
- Memory Leak Prevention: Advanced cleanup procedures prevent WebSocket resource leaks
- Thread-Safe Operations: All WebSocket operations properly synchronized for multi-threaded safety
- β Fixed encryption coordination with automatic parameter validation
- β Enhanced WebSocket reconnection with exponential backoff
- β Bulletproof WebSocket client disconnect handling
- β Advanced connection state management with human-readable descriptions
- β Improved error handling and WebSocket event management
- β Enhanced encryption context management with salt coordination (Just a hardcoded Salt on both client/server) May enhance the way we generate these salts in the future!
- Issues: Report bugs via GitHub Issues
- Questions: Community support available
- Contributing: Pull requests welcome!
- Discord: bitmasterxor
Open Source - Free to distribute and use in commercial and personal projects!
π Ready to Build High-Performance WebSocket Applications?
Download β’ Install β’ Build Amazing Real-Time Apps!
Made By BitmasterXor And Friends With β€οΈ for the Delphi Community