TsgcWebSocketClientMethods › Disconnect

Disconnect Method

Closes the WebSocket connection synchronously and blocks the caller until the disconnection completes or the timeout elapses.

Syntax

public bool Disconnect(int aTimeout = 10000);

Parameters

NameTypeDescription
aTimeoutconst IntegerMaximum time in milliseconds to wait for the connection to be closed. Defaults to 10000 (10 seconds).

Return Value

True when the client has been fully disconnected within the timeout; False if the timeout expired first. (Boolean)

Remarks

Disconnect is the blocking counterpart to setting Active := False. It clears Active and then waits on an internal event until the disconnect handshake finishes or the timeout fires. If the client is already disconnected, the method returns True immediately. When Options.CleanDisconnect is enabled, a WebSocket close frame is sent to the server before the socket is torn down. Use Stop instead when you need a non-blocking disconnect from a secondary thread.

Example


if (oClient.Disconnect(10000) == true)
  ShowMessage("Disconnected");
else
  ShowMessage("Not Disconnected");

Back to Methods