0

Thanks to the help of many Stackoverflow contributors, I have successfully completed my Windows VCL project to, ping a number of IP Addresses, add them to an SQLtable, sort them by ping time and automatically set the IpV4 DNS settings to the fastest 2 addresses. This works perfectly under Windows.

I am now trying to create a similar application running under Android. I am using idIcmpclient to ping the addreses and pick up the IdICMPClient1.ReplyStatus.MsRoundTripTime. The code compiles and installs on my Android test device(s). However when run under Android, I receive a Socket #1 error. The testing code is below.

procedure TForm1.Button1Click(Sender: TObject);
var
  ipAddr: string;
begin
  ipAddr := '188.132.234.170';
  IdIcmpClient1.ReceiveTimeout := 200;
  IdIcmpClient1.Host := ipAddr;
  IdIcmpClient1.ping();
  if IdIcmpClient1.ReplyStatus.ReplyStatusType = rsEcho then
  begin
    Memo1.Lines.Add(IntToStr(IdIcmpClient1.ReplyStatus.MsRoundTripTime));
    Memo1.Lines.Add(IdIcmpClient1.ReplyStatus.Msg)
  end
  else if IdIcmpClient1.ReplyStatus.ReplyStatusType = rsTimeout then
  begin
    // have a timeout, link is down
  end
  else
  begin
    // do something else
  end;
end;

I have looked to see if there are peculiarities with IdIcmpclient and other OS's and have found out that it does not work with iOS , something to do with Raw Sockets.

I am assuming that maybe the same case applies to Android, which leaves me with a bit of a problem and possibly an untimely end to my new Android project.

If IdIcmpClient.Ping does not work under Android, is there an alternative method to Ping addresses and get the return times.

Any help much appreciated

WobblyBob
  • 109
  • 1
  • 12
  • TIdIcmpClient uses a RAW socket to implement its pinging. You need admin rights to use RAW sockets on most platforms, including Windows. You will likely have to use platform specific APIs to get around that limitation. – Remy Lebeau Aug 05 '19 at 18:14
  • @Remy Hi Remy, many thanks for you response. I have spent a few hours trawling and looking for info on accessing Android API's with Delphi. All I can come up with at the moment is [Link](http://www.fmxuniversity.com/access-the-android-sdk-api-from-your-delphi-firemonkey-apps/) but this is rather old and I cannot find any references to Pinging. I shall continue on my quest – WobblyBob Aug 06 '19 at 09:44
  • 1
    See [How to Ping External IP from Java Android](https://stackoverflow.com/questions/3905358/) and [Java2OP.exe, the Native Bridge File Generator for Android](http://docwiki.embarcadero.com/RADStudio/en/Java2OP.exe,_the_Native_Bridge_File_Generator_for_Android) – Remy Lebeau Aug 06 '19 at 16:18

0 Answers0