TsgcWebSocketClient事件 › OnConnect

OnConnect 事件

当与服务器的 WebSocket 连接成功建立时触发。

语法

property OnConnect: TsgcWSConnectEvent;
// TsgcWSConnectEvent = procedure(Connection: TsgcWSConnection) of object

默认值

备注

OnConnect 在 TCP 套接字打开且 WebSocket 握手成功完成(即客户端可以开始发送消息)之后触发。通过 Active 属性或 Start 打开连接时,请在此事件触发后再调用 WriteData;同步的 Connect 方法在 OnConnect 已分发之后才返回。Connection 参数公开当前会话(远程地址、协议、身份验证状态等)。

示例


procedure OnConnect(Connection: TsgcWSConnection);
begin
  Log('Connected to ' + Connection.PeerIP);
  Connection.WriteData('Hello from client');
end;

返回事件