TsgcTCPClient › 事件 › OnConnect
当与服务器的 TCP 连接成功建立时触发。
property OnConnect: TsgcWSConnectEvent;
// TsgcWSConnectEvent = procedure(Connection: TsgcWSConnection) of object
—
OnConnect 在 TCP 套接字打开后(启用 TLS 时,在 TLS 握手完成后)立即触发。由于 TsgcTCPClient 使用原始 TCP,因此没有 WebSocket 升级步骤,连接在此事件触发时即可发送字节。在通过 Active 属性或 Start 打开连接时,请等待 OnConnect 后再调用 WriteData;同步的 Connect 方法仅在 OnConnect 已分发后才返回。Connection 参数公开活动会话(远程地址、协议、TLS 状态...)。
procedure OnConnect(Connection: TsgcWSConnection);
begin
Log('Connected to ' + Connection.PeerIP);
Connection.WriteData('Hello from TCP client');
end;