TsgcWebSocketClientEvents › OnBeforeConnect

OnBeforeConnect Event

Fires before the client tries to connect to the server.

Syntax

public event TsgcWSOnBeforeConnectEventHandler OnBeforeConnect;
// delegate void TsgcWSOnBeforeConnectEventHandler(TObject Sender)

Default Value

Remarks

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.

Example


void OnBeforeConnect(TObject Sender)
{
  ((TsgcWebSocketClient)Sender).Host = "fallback.example.com";
  ((TsgcWebSocketClient)Sender).Port = 443;
}

Back to Events