Tuto
Tuto

Reputation: 21

Delphi how to check if Datasnap server is running programmatically

i´m trying to know (test) programmatically if my Datasnap server is running before connect with my client app, to prevent error from it. Some ideas?

Delphi XE 10.1 Server on AWS amazon (Win server 2012 R2) Database (Mysql) on my shared server. Client Apps: Win/IOs/Android

Best Regards

Upvotes: 0

Views: 1144

Answers (1)

Tuto
Tuto

Reputation: 21

I've found this, and work for me:

Check remote port access using Delphi - Telnet style

So, here is the code:

//uses: IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient

function IsPortActive(AHost : string; APort : Word): boolean;
var
  IdTCPClient : TIdTCPClient;
begin
  Result := False;
  try
    IdTCPClient := TIdTCPClient.Create(nil);
    try
      IdTCPClient.Host := AHost;
      IdTCPClient.Port := APort;
      IdTCPClient.Connect;
      Result := True;
    finally
      IdTCPClient.DisposeOf;
    end;
  except
    //Ignore exceptions
 end;
end;    

Upvotes: 2

Related Questions