Skip to main content
Table of Contents

TMS FNC WebSocket Client

TTMSFNCWebsocketClient is a headless component for connecting to WebSocket servers and exchanging text and binary messages over a persistent, bidirectional connection. It implements the RFC 6455 WebSocket protocol, including the handshake, masking, fragmentation, ping and pong, and the closing handshake, over plain ws:// or TLS-secured wss:// connections. Use it whenever a VCL or FMX application must receive data the moment a server pushes it.

Documentation

Start here Use when
Get started Install, configure, connect to a server, and send your first message.
Guides Task guides: connecting, messaging, connection health, and secure connections.
API reference Full property, method, and event reference.

Supported frameworks

Framework Support
VCL Win32 and Win64.
FMX Windows, macOS, iOS, Android, and Linux.
TMS WEB Core Not available; use TMS WEB Core's TWebSocketClient component in browser applications.

Minimal example

Create the client, point it at a server, wire the connection events, and connect:

Connect to a WebSocket serverPascal
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;

API map

Role Classes
Main component TTMSFNCWebsocketClient
Connection TTMSFNCWebSocketClientConnection (the active connection), derived from TTMSFNCWebSocketConnection (send, ping, pong, and close frames)
Handshake TTMSFNCWebSocketHandshakeRequest, TTMSFNCWebSocketHandshakeResponse
Frames and options TTMSFNCWebSocketFrame, TTMSFNCWebSocketFrameTypes, TTMSFNCWebSocketOption, TTMSFNCWebSocketIncomingResult
Message reading TTMSFNCWebSocketMessageDriver, TTMSFNCWebSocketThreadedMessageDriver
Event types TTMSFNCWebSocketMessageEvent, TTMSFNCWebSocketBinDataEvent, TTMSFNCWebSocketControlEvent, TTMSFNCWebSocketNotifyEvent, TTMSFNCWebSocketClientCreateIOHandlerEvent
Exceptions TTMSFNCWebSocketException, TTMSFNCWebSocketHandshakeException

Guides

Area Guide
Connection lifecycle Connecting — URL anatomy, Active and Connect, the handshake, closing and aborting.
Messaging Sending and receiving — text and binary messages, masking, frames, message checking, and the event thread.
Reliability Connection health — ping and pong, manual pong replies, and detecting a lost connection.
Security Secure connections — wss://, OpenSSL deployment, and custom IO handlers for OpenSSL 3.x.

See Also