Getting started with TMS FNC WebSocket Server
Prerequisites
- TMS FNC Core and TMS FNC WebSocket installed (see Installation).
Add the component
- Drop
TTMSFNCWebSocketServerfrom the TMS FNC WebSocket palette page onto a form, or create one at runtime. - Set
Portto the port the server should listen on. - Wire
OnConnect,OnDisconnect, andOnMessageReceived, then setActive := Trueto start listening.
The minimal server — port, connection events, and starting it:
procedure TForm1.StartServer;
begin
FServer := TTMSFNCWebSocketServer.Create(Self);
FServer.Port := 5050; // default is 8888
FServer.PathName := 'chat'; // clients connect to ws://<host>:5050/chat
FServer.AutoSyncEvents := True; // raise events on the main thread
FServer.OnConnect := ServerConnect;
FServer.OnDisconnect := ServerDisconnect;
FServer.OnMessageReceived := ServerMessageReceived;
FServer.Active := True; // begin listening for clients
end;
procedure TForm1.StopServer;
begin
FServer.Active := False; // stop listening and drop all clients
end;
procedure TForm1.ServerConnect(Sender: TObject; AConnection: TTMSFNCWebSocketConnection);
begin
// A TCP connection arrived; the WebSocket handshake has not happened yet.
Log('Connection from ' + AConnection.PeerIP);
end;
procedure TForm1.ServerDisconnect(Sender: TObject; AConnection: TTMSFNCWebSocketConnection);
begin
Log('A client disconnected');
end;
void __fastcall TForm1::StartServer()
{
FServer = new TTMSFNCWebSocketServer(this);
FServer->Port = 5050; // default is 8888
FServer->PathName = "chat"; // clients connect to ws://<host>:5050/chat
FServer->AutoSyncEvents = true; // raise events on the main thread
FServer->OnConnect = ServerConnect;
FServer->OnDisconnect = ServerDisconnect;
FServer->OnMessageReceived = ServerMessageReceived;
FServer->Active = true; // begin listening for clients
}
void __fastcall TForm1::StopServer()
{
FServer->Active = false; // stop listening and drop all clients
}
void __fastcall TForm1::ServerConnect(TObject *Sender, TTMSFNCWebSocketConnection *AConnection)
{
// A TCP connection arrived; the WebSocket handshake has not happened yet.
Log("Connection from " + AConnection->PeerIP);
}
void __fastcall TForm1::ServerDisconnect(TObject *Sender, TTMSFNCWebSocketConnection *AConnection)
{
Log("A client disconnected");
}
Next steps
- Guides — running a server (including TLS) and broadcasting between clients.
- API reference — full class, property, method, and event reference.