Ping with Synapse lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- ElRon21 · 2017-12-26 14:31 Hello, first of all, excuse my bad english. I'm new to programming. I've tried a long time to achieve a succesful ping. Here is my code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,  StdCtrls, blcksock, synautil, synsock, pingsend; type   { TForm1 }   TForm1 = class(TForm)    Button_close: TButton;    Button_ping: TButton;    Edit1: TEdit;    Memo1: TMemo;    procedure Button_closeClick(Sender: TObject);    procedure Button_pingClick(Sender: TObject);  private    { private declarations }  public    { public declarations }  end;   { TPINGSend }   TPINGSend = class(TSynaClient)    function Ping(const Host: string): Boolean;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button_closeClick(Sender: TObject);begin  Application.Mainform.Close;end; procedure TForm1.Button_pingClick(Sender: TObject);var  PingSend:TPingSend;  ip: string;begin  Memo1.Clear;  ip:=Edit1.Text;  PingSend:=TPingSend.Create;   Try       PingSend.Timeout :=750;       Memo1.Lines.Append(BoolToStr(PingSend.Ping(ip)));   finally       PingSend.Free;   end;end;  { TPINGSend } function TPINGSend.Ping(const Host: string): Boolean;begin end; end. When i click the "Ping"-Button, i always get a "0" in Memo1, no matter which Host i enter. Can anybody help me please? ---------------------------------------------------------------------- ElRon21 · 2017-12-26 23:05 Update: I‘ve tried other functions (pinghost, traceroutehost) with the same result. And another thing: Now the result of the function ping is always „-1“ (true), no matter which host I enter im Edit1. Any ideas what‘s wrong? ---------------------------------------------------------------------- Thaddy · 2017-12-26 23:35 In this case -1 does not mean true but fail, as per the synapse documentation. I wrote a simpler version and it also fails: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program pingme;{$ifdef windows}{$apptype console}{{$endif}{$ifdef fpc}{$mode delphi}{$H+}{$I-}{$endif}uses {$ifdef unix}cthreads,{$endif}sysutils,pingsend;var i:integer;begin  for i := 1 to 5 do  begin   // all three should work:    writeln(PingHost('http://thaddy.com')); // this is my own server and ping is allowed    writeln(PingHost('http:/www.thaddy.com')); // this is my own server and ping is allowed    writeln(PingHost('thaddy.com')); // this is my own server and ping is allowed    sleep(1000);  end;end.Which means there is a bug in Synapse. Probably a regression. I will look into it tommorow. It is too late here now. ---------------------------------------------------------------------- Lutz Mändle · 2017-12-26 23:44 Ping needs elevated rights. ---------------------------------------------------------------------- Jurassic Pork · 2017-12-27 06:29 hello, Quote from: Thaddy on December 27, 2017, 12:35:47 amWhich means there is a bug in Synapse. Probably a regression. I will look into it tommorow. It is too late here now. bug is often between the chair and the keyboard especially when it is late in the night  http://xxxxxx.yyy isn't a valid address. DNS servers don't know http:// . ElRon21 to have more infos about a ping request with synapse, you can use a code like this : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program pingme;{$mode objfpc}{$H+}uses sysutils,pingsend, laz_synapse;var i:integer;var myPingSend: TPingSend;begin   myPingSend := TPINGSend.Create;  try  myPingSend.Timeout := 2000;   if myPingSend.Ping('lazarus.freepascal.org') = True then    begin     writeln('Reply from ' +  myPingSend.ReplyFrom +     ' in: ' + IntToStr(myPingSend.PingTime) + ' ms');    end    else    begin      writeln('No response from ' + myPingSend.ReplyFrom +      ' in: ' + IntToStr(myPingSend.Timeout) + ' ms');      writeln('error: ' + myPingSend.ReplyErrorDesc );    end;   finally     myPingSend.Free;   //Readln;   end;end. Friendly, J.P ---------------------------------------------------------------------- Thaddy · 2017-12-27 08:10 @Jurrasic Pork: The issue is that PingHost (the encapsulation) does not work as advertised. I know that using the TPingSend class works, but only on windows. otherwise the timeout isn't working. It times out immediately and that is a cross-platform regression. Your code also does not work on (arm) Linux. ---------------------------------------------------------------------- Jurassic Pork · 2017-12-27 11:18 Quote from: Thaddy on December 27, 2017, 09:10:10 am@Jurrasic Pork: The issue is that PingHost (the encapsulation) does not work as advertised. I know that using the TPingSend class works, but only on windows. otherwise the timeout isn't working. It times out immediately and that is a cross-platform regression. Your code also does not work on (arm) Linux. On Ubuntu 16.04 with Lazarus 1.8.0, my code only works if i launch the program with elevated rights(see attachment). ---------------------------------------------------------------------- Thaddy · 2017-12-27 11:23 Yes. That's strange, my code also works. There should not be a usermode issue, though. ---------------------------------------------------------------------- Jurassic Pork · 2017-12-27 11:35 thaddy have a look in this thread  . you give us an analysis ---------------------------------------------------------------------- Thaddy · 2017-12-27 14:08 Ok, I already did it myself... http://forum.lazarus.freepascal.org/ind ex.php/topic,29322.msg185030.html#msg185030