TsgcWebSocketClient › Events › OnConnect
Fires when a WebSocket connection to the server has been successfully established.
property OnConnect: TsgcWSConnectEvent;
// TsgcWSConnectEvent = procedure(Connection: TsgcWSConnection) of object
—
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...).
procedure OnConnect(Connection: TsgcWSConnection);
begin
Log('Connected to ' + Connection.PeerIP);
Connection.WriteData('Hello from client');
end;