TsgcTCPClient › Events › OnConnect
Fires when the TCP connection to the server has been successfully established.
property OnConnect: TsgcWSConnectEvent;
// TsgcWSConnectEvent = procedure(Connection: TsgcWSConnection) of object
—
OnConnect is raised as soon as the TCP socket has been opened (and, when TLS is enabled, after the TLS handshake has completed). Because TsgcTCPClient speaks raw TCP there is no WebSocket upgrade step, so the connection is ready to send bytes the moment this event fires. Wait for OnConnect before calling WriteData when opening the connection through the Active property or Start; the synchronous Connect method returns only after OnConnect has already been dispatched. The Connection parameter exposes the active session (remote address, protocol, TLS state...).
procedure OnConnect(Connection: TsgcWSConnection);
begin
Log('Connected to ' + Connection.PeerIP);
Connection.WriteData('Hello from TCP client');
end;