TsgcWebSocketLoadBalancerServer事件 › OnClientConnect

OnClientConnect 事件

当下游客户端完成与负载均衡器的 WebSocket 握手并与后端服务器配对时触发。

语法

property OnClientConnect: TsgcWSLBClientConnectionEvent;
// TsgcWSLBClientConnectionEvent = procedure(ServerConnection: TsgcWSConnection; ClientConnection: TsgcWSLoadBalancerClientConnection) of object

默认值

备注

每次接受客户端会话并路由到某个已注册后端时,触发 OnClientConnect。ServerConnection 是将接收转发流量的后端 TsgcWSConnection,而 ClientConnection 是封装下游会话并公开客户端元数据(Guid、PeerIP、协议、绑定、选定服务器)的 TsgcWSLoadBalancerClientConnection。使用此事件记录客户端到后端的分配、构建仪表板或填充会话映射。此事件不同于 OnConnect,后者继承自 HTTP 服务器,在套接字级别接受任何连接时触发。

示例


procedure OnClientConnect(ServerConnection: TsgcWSConnection;
  ClientConnection: TsgcWSLoadBalancerClientConnection);
begin
  Log(Format('Client %s routed to backend %s',
    [ClientConnection.Guid, ServerConnection.Guid]));
end;

返回事件