TsgcWebSocketClientEvents › OnConnect

OnConnect Event

Fires when a WebSocket connection to the server has been successfully established.

Syntax

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

Default Value

Remarks

OnConnect is raised after the TCP socket is open and the WebSocket handshake has completed successfully, meaning the client can start sending messages. Wait for this event 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, authentication state...).

Example


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

Back to Events