TsgcTCPClient › Events › OnConnect

OnConnect Event

Fires when the TCP connection to the server has been successfully established.

Syntax

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

Default Value

—

Remarks

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...).

Example


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

Back to Events