TsgcWebSocketClient › Events › OnBeforeConnect
Fires before the client tries to connect to the server.
property OnBeforeConnect: TsgcWSOnBeforeConnectEvent;
// TsgcWSOnBeforeConnectEvent = procedure(Sender: TObject) of object
—
OnBeforeConnect is raised just before the client opens a TCP connection to the server, which gives the application a last chance to update connection properties such as Host, Port, URL, Proxy or authentication credentials. The event is also fired before every WatchDog reconnection attempt, so it is a convenient place to switch to a fallback endpoint when the primary server is unreachable. The handler receives only the Sender (the TsgcWebSocketClient instance); there is no Connection object yet because the socket has not been created.
procedure OnBeforeConnect(Sender: TObject);
begin
TsgcWebSocketClient(Sender).Host := 'fallback.example.com';
TsgcWebSocketClient(Sender).Port := 443;
end;