TsgcWebSocketLoadBalancerServerEvents › OnDisconnect

OnDisconnect 事件

当负载均衡器接受的任何 WebSocket 连接关闭时触发。

语法

property OnDisconnect: TsgcWSDisconnectEvent;
// TsgcWSDisconnectEvent = procedure(Connection: TsgcWSConnection; Code: Integer) of object

默认值

备注

OnDisconnect 继承自底层服务器,每当连接(客户端或后端)关闭时触发。Code 携带 WebSocket 关闭代码(正常关闭为 1000,套接字中断时为 1006)。不要在此处理程序中尝试向连接发回数据,会话已经结束。若需区分客户端和后端生命周期的通知,请使用 OnClientDisconnect 和 OnServerDisconnect,它们提供负载均衡器特定的上下文。

示例


procedure OnDisconnect(Connection: TsgcWSConnection; Code: Integer);
begin
  Log(Format('Disconnected %s (code=%d)', [Connection.Guid, Code]));
end;

返回事件