Test Whether Server is Active

TECH TIP: Testing Whether the Server is Active

The following code show how to test whether the server is active.

This code uses the TrsClientTcpSocket component to connect to the server. The example shows the code within the context of a Button.OnClick event-handler. However, you could also code this to fire at a specified interval by using a TTimer component.

uses
  rsClientTcpSocket, rsExceptions;

procedure TForm1.Button1Click(Sender: TObject);
var
  lClientSocket: TrsClientTcpSocket;
begin
  lClientSocket := TrsClientTcpSocket.Create;

  try
    {configur the connection parameters}
    {lClientSocket.Connection := rsClientReport.Connection; }

    try
      lClientSocket.Active := True;
    except on EClientError do
      ShowMessage('Server is down');
    end;

  finally
    lClientSocket.Free;
  end;

end;