* * *

Author Topic: Ping with Synapse  (Read 2013 times)

ElRon21

  • Newbie
  • Posts: 4
Ping with Synapse
« on: December 26, 2017, 03:31:38 pm »
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]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.   StdCtrls, blcksock, synautil, synsock, pingsend;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button_close: TButton;
  17.     Button_ping: TButton;
  18.     Edit1: TEdit;
  19.     Memo1: TMemo;
  20.     procedure Button_closeClick(Sender: TObject);
  21.     procedure Button_pingClick(Sender: TObject);
  22.   private
  23.     { private declarations }
  24.   public
  25.     { public declarations }
  26.   end;
  27.  
  28.   { TPINGSend }
  29.  
  30.   TPINGSend = class(TSynaClient)
  31.     function Ping(const Host: string): Boolean;
  32.   end;
  33.  
  34. var
  35.   Form1: TForm1;
  36.  
  37. implementation
  38.  
  39. {$R *.lfm}
  40.  
  41. { TForm1 }
  42.  
  43. procedure TForm1.Button_closeClick(Sender: TObject);
  44. begin
  45.   Application.Mainform.Close;
  46. end;
  47.  
  48. procedure TForm1.Button_pingClick(Sender: TObject);
  49. var
  50.   PingSend:TPingSend;
  51.   ip: string;
  52. begin
  53.   Memo1.Clear;
  54.   ip:=Edit1.Text;
  55.   PingSend:=TPingSend.Create;
  56.    Try
  57.        PingSend.Timeout :=750;
  58.        Memo1.Lines.Append(BoolToStr(PingSend.Ping(ip)));
  59.    finally
  60.        PingSend.Free;
  61.    end;
  62. end;
  63.  
  64.  
  65. { TPINGSend }
  66.  
  67. function TPINGSend.Ping(const Host: string): Boolean;
  68. begin
  69.  
  70. end;
  71.  
  72. end.  
  73.  

When i click the "Ping"-Button, i always get a "0" in Memo1, no matter which Host i enter.
Can anybody help me please?
« Last Edit: December 27, 2017, 12:36:03 am by ElRon21 »

ElRon21

  • Newbie
  • Posts: 4
Re: Ping with Synapse
« Reply #1 on: December 27, 2017, 12:05:03 am »
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

  • Hero Member
  • *****
  • Posts: 6370
Re: Ping with Synapse
« Reply #2 on: December 27, 2017, 12:35:47 am »
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]
  1. program pingme;
  2. {$ifdef windows}{$apptype console}{{$endif}
  3. {$ifdef fpc}{$mode delphi}{$H+}{$I-}{$endif}
  4. uses {$ifdef unix}cthreads,{$endif}sysutils,pingsend;
  5. var i:integer;
  6. begin
  7.   for i := 1 to 5 do
  8.   begin
  9.    // all three should work:
  10.     writeln(PingHost('http://thaddy.com')); // this is my own server and ping is allowed
  11.     writeln(PingHost('http:/www.thaddy.com')); // this is my own server and ping is allowed
  12.     writeln(PingHost('thaddy.com')); // this is my own server and ping is allowed
  13.     sleep(1000);
  14.   end;
  15. end.
Which means there is a bug in Synapse. Probably a regression.
I will look into it tommorow. It is too late here now.
« Last Edit: December 27, 2017, 12:42:49 am by Thaddy »
I am enjoining wine, not whine....

Lutz Mändle

  • New member
  • *
  • Posts: 45
Re: Ping with Synapse
« Reply #3 on: December 27, 2017, 12:44:46 am »
Ping needs elevated rights.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 715
Re: Ping with Synapse
« Reply #4 on: December 27, 2017, 07:29:15 am »
hello,
Which 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  ;D
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]
  1. program pingme;
  2. {$mode objfpc}{$H+}
  3. uses sysutils,pingsend, laz_synapse;
  4. var i:integer;
  5. var myPingSend: TPingSend;
  6. begin
  7.    myPingSend := TPINGSend.Create;
  8.   try
  9.   myPingSend.Timeout := 2000;
  10.    if myPingSend.Ping('lazarus.freepascal.org') = True then
  11.     begin
  12.      writeln('Reply from ' +  myPingSend.ReplyFrom +
  13.      ' in: ' + IntToStr(myPingSend.PingTime) + ' ms');
  14.     end
  15.     else
  16.     begin
  17.       writeln('No response from ' + myPingSend.ReplyFrom +
  18.       ' in: ' + IntToStr(myPingSend.Timeout) + ' ms');
  19.       writeln('error: ' + myPingSend.ReplyErrorDesc );
  20.     end;
  21.    finally
  22.      myPingSend.Free;
  23.      //Readln;
  24.    end;
  25. end.

Friendly, J.P
« Last Edit: December 27, 2017, 07:31:55 am by Jurassic Pork »

Thaddy

  • Hero Member
  • *****
  • Posts: 6370
Re: Ping with Synapse
« Reply #5 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.
I am enjoining wine, not whine....

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 715
Re: Ping with Synapse
« Reply #6 on: December 27, 2017, 12:18:36 pm »
@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).

« Last Edit: December 27, 2017, 12:21:32 pm by Jurassic Pork »

Thaddy

  • Hero Member
  • *****
  • Posts: 6370
Re: Ping with Synapse
« Reply #7 on: December 27, 2017, 12:23:43 pm »
Yes. That's strange, my code also works. There should not be a usermode issue, though.
« Last Edit: December 27, 2017, 12:26:24 pm by Thaddy »
I am enjoining wine, not whine....

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 715
Re: Ping with Synapse
« Reply #8 on: December 27, 2017, 12:35:59 pm »
thaddy have a look in this thread  . you give us an analysis    ;)
« Last Edit: December 27, 2017, 12:37:33 pm by Jurassic Pork »

Thaddy

  • Hero Member
  • *****
  • Posts: 6370
Re: Ping with Synapse
« Reply #9 on: December 27, 2017, 03:08:39 pm »
I am enjoining wine, not whine....

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus