TsgcWebSocketLoadBalancerServer › Events › OnClientMessage
Fires when a text frame is received from a downstream client before it is forwarded to the selected backend server.
property OnClientMessage: TsgcWSLBServerMessageEvent;
// TsgcWSLBServerMessageEvent = procedure(Connection: TsgcWSConnection; Text: String; var Handled: Boolean) of object
—
OnClientMessage is raised for every text WebSocket frame received from a balanced client on its way to the backend server. Connection identifies the downstream client session and Text carries the decoded UTF-8 payload. Set Handled to True to consume the message inside the load balancer (no relay to the backend happens in that case), typically when the load balancer answers control messages on behalf of the backend or filters out invalid content. Leave Handled False (default) to let the load balancer forward the message unchanged.
procedure OnClientMessage(Connection: TsgcWSConnection; Text: String;
var Handled: Boolean);
begin
// answer ping messages directly from the load balancer
if SameText(Text, 'ping') then
begin
Connection.WriteData('pong');
Handled := True;
end;
end;