TsgcWebSocketProxyServerEvents › OnMessage

OnMessage Event

Fires every time a downstream WebSocket client sends a text message, before the proxy forwards it upstream.

Syntax

property OnMessage: TsgcWSMessageEvent;
// TsgcWSMessageEvent = procedure(Connection: TsgcWSConnection; const Text: string) of object

Default Value

Remarks

OnMessage is raised once a complete text frame has been received from a downstream WebSocket client. The Text parameter carries the decoded UTF-8 string and the Connection parameter identifies the sender session. The proxy relays this payload to the upstream TCP server (Proxy.Host, Proxy.Port) right after the handler returns, so it is a convenient place to inspect, log, or modify the message before it is forwarded. By default NotifyEvents is neAsynchronous and the handler runs synchronized with the main thread, which makes it safe to update UI controls; for high-throughput proxies set NotifyEvents to neNoSync to dispatch in the connection thread and implement your own synchronization. If Options.FragmentedMessages is frgOnlyFragmented the event is not raised and the payload is delivered through OnFragmented instead.

Example


procedure OnMessage(Connection: TsgcWSConnection; const Text: string);
begin
  ShowMessage('Message Received from Client: ' + Text);
end;

Back to Events