TsgcWebSocketClient › Methods › Ping
Sends a WebSocket ping frame to the server and returns immediately without waiting for the pong response.
public void Ping(string aText = '');
| Name | Type | Description |
|---|---|---|
aText | const String | Optional payload to carry inside the ping frame; pass an empty string to send a ping with no payload. |
This overload fires the ping and returns straight away, without blocking the caller or waiting for the matching pong. It is a no-op when the client is not connected. Any pong received from the server is delivered asynchronously through the standard connection events. Internally exceptions are trapped and routed to OnError. Use the timeout overload of the other overload when you need confirmation that the peer is still reachable.
oClient.Ping("keepalive");
public bool Ping(int aTimeout, string aText = '');
| Name | Type | Description |
|---|---|---|
aTimeout | Integer | Maximum time in milliseconds to wait for the pong reply before giving up. |
aText | const String | Optional payload to carry inside the ping frame; pass an empty string to send a ping with no payload. |
True if the server replied with a matching pong inside the timeout window; False otherwise. When False is returned the client may choose to close the connection because the peer is considered unreachable. (Boolean)
This overload blocks the calling thread until either the pong arrives or the timeout elapses, so it is useful for interactive liveness checks. The method returns False immediately when the client is not connected. Exceptions raised by the underlying socket are caught and forwarded to OnError. For a fire-and-forget ping that does not block, use the parameterless the other overload overload instead.
if (oClient.Ping(5000, "healthcheck") == false)
oClient.Disconnect();