Skip to main content
Table of Contents

Getting started with TMS FNC WebSocket Client

Prerequisites

  • TMS FNC Core and TMS FNC WebSocket installed (see Installation).

Add the component

  1. Drop TTMSFNCWebsocketClient from the TMS FNC WebSocket palette page onto a form, or create one at runtime.
  2. Set HostName to the server address and Port to the server port.
  3. Wire OnConnect, OnDisconnect, and OnMessageReceived, then call Connect.

The minimal client — host, port, connection events, and connecting:

Connect to a WebSocket serverPascalC++
procedure TForm1.SetupClient;
begin
  FClient := TTMSFNCWebsocketClient.Create(Self);
  FClient.HostName := 'localhost';
  FClient.Port := 5050;

  FClient.OnConnect := ClientConnect;
  FClient.OnDisconnect := ClientDisconnect;
  FClient.OnMessageReceived := ClientMessageReceived;

  // Connect blocks until the TCP connection and the WebSocket handshake are
  // done. OnConnect fires before it returns; Active stays False when the
  // server rejected the handshake.
  FClient.Connect;
  if not FClient.Active then
    ShowMessage('The server did not accept the WebSocket handshake.');
end;

procedure TForm1.ClientConnect(Sender: TObject; AConnection: TTMSFNCWebSocketConnection);
begin
  // Connected - it is now safe to Send.
  sendBtn.Enabled := True;
end;

procedure TForm1.ClientDisconnect(Sender: TObject; AConnection: TTMSFNCWebSocketConnection);
begin
  sendBtn.Enabled := False;
end;
void __fastcall TForm1::SetupClient()
{
  FClient = new TTMSFNCWebsocketClient(this);
  FClient->HostName = "localhost";
  FClient->Port = 5050;

  FClient->OnConnect = ClientConnect;
  FClient->OnDisconnect = ClientDisconnect;
  FClient->OnMessageReceived = ClientMessageReceived;

  // Connect blocks until the TCP connection and the WebSocket handshake are
  // done. OnConnect fires before it returns; Active stays False when the
  // server rejected the handshake.
  FClient->Connect();
  if (!FClient->Active)
    ShowMessage("The server did not accept the WebSocket handshake.");
}

void __fastcall TForm1::ClientConnect(TObject *Sender, TTMSFNCWebSocketConnection *AConnection)
{
  // Connected - it is now safe to Send.
  sendBtn->Enabled = true;
}

void __fastcall TForm1::ClientDisconnect(TObject *Sender, TTMSFNCWebSocketConnection *AConnection)
{
  sendBtn->Enabled = false;
}

Next steps

  • Guides — connecting (including TLS) and sending and receiving messages.
  • API reference — full class, property, method, and event reference.