Re: [twsocket] TPing, PingThrd1...
On 08/09/2013 18:39, zayin wrote: A failure message can come sooner if there is a failure in Winsock. Situations where this will occur is if you have no network connectivity (General Error), there is no route to host or TTL expired in transit (too many hops). In cases like this, the TCP/IP stack won't wait until the requested delay to return the failure. As was posed in the first message: "So, really the timeout is the maximum time to wait and the response could come much sooner?" This is true. A failure message can come much sooner than the timeout limit. Ciao, Mark -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] TPing, PingThrd1...
Hi, A follow-up. After more testing and code writing I have found the timeout does work, for the most part. Just because a device does not respond to a ping does not equal the timeout will occur. Another device can respond with the error. That is what seems to be the case. I did not WireShark it to verify. This is what appears to be the case after much testing. Some routers/cable modems with multiple ports will respond with a failure message before the timeout limit is reached. And some routers/cable modems have ICMP disabled and respond with a failure message for ICMP ping traffic. As was posed in the first message: "So, really the timeout is the maximum time to wait and the response could come much sooner?" This is true. A failure message can come much sooner than the timeout limit. Ciao, Mark -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] TPing, PingThrd1...
On 03/09/2013 21:16, zayin wrote: I need a very simple ping test, threaded. The demo I found works, expect altering the timeout does not change the length of time to wait for a response after the ICMP echo is sent. Mark I currently use this in production. It's a custom app I've written which has a listview full of IP addresses, and columns for number of failures, last ping response time and date. Below is the Thread unit, and at the bottom I'll show how I create my threads in my main unit. There's obviously a lot here you don't need, but you can just use the parts you need. As you can see, I set my timeout to be 10 seconds, and I've verified that this works. Hope it helps! Lester unit IPMonUnit2; interface uses System.Classes, System.SysUtils, Vcl.ComCtrls, OverbyteIcsWndControl, OverbyteIcsPing; type TCustomPing = class(TPing) public FStatus : Integer; end; TICMP = class(TThread) private PingExternal : TCustomPing; PingInternal : TCustomPing; FListItem : TListItem; FNumFailures : Integer; procedure SetListItem(Const Value: TListItem); procedure SetNumFailures(Const Value: Integer); procedure PrepareICMP; procedure DoICMPs; procedure EnterResults; { Private declarations } protected procedure Execute; override; public constructor Create(CreateSuspended: Boolean); destructor Destroy; property ListItem: TListItem read FListItem write SetListItem; property NumFailures: Integer read FNumFailures write SetNumFailures; end; implementation procedure TICMP.SetListItem(const Value: TListItem); begin FListItem := Value; end; procedure TICMP.SetNumFailures(const Value: Integer); begin FNumFailures := Value; end; constructor TICMP.Create(Createsuspended: Boolean); begin inherited; FreeOnTerminate := True; end; destructor TICMP.Destroy; begin end; procedure TICMP.PrepareICMP; begin if Assigned(FListItem) then Begin PingExternal.Address := FListItem.SubItems.Strings[0]; PingInternal.Address := FListItem.SubItems.Strings[2]; End Else Begin End; end; Function DoPing(Ping : TCustomPing) : Boolean; Var Counter : Integer; begin if Ping.Address = '' then Result := True Else Begin Counter := 0; Repeat Counter := Counter + 1; Ping.FStatus := Ping.Ping; Until (Counter >= 3) or (Ping.FStatus = 1); if (Ping.Reply.Status = 0) and (Ping.FStatus = 1) then Result := True Else Result := False; End; end; procedure TICMP.DoICMPs; Var Failures : Integer; begin Failures := 0; if NOT DoPing(PingExternal) Then Inc(Failures); if NOT DoPing(PingInternal) Then Inc(Failures); SetNumFailures(Failures); end; procedure TICMP.EnterResults; begin if PingExternal.Address > '' then If (PingExternal.Reply.Status = 0) and (PingExternal.FStatus = 1) Then Begin FListItem.SubItems.Strings[1] := IntToStr(PingExternal.Reply.RTT); End Else Begin FListItem.SubItems.Strings[1] := 'Down'; End; if PingInternal.Address > '' then If (PingInternal.Reply.Status = 0) and (PingInternal.FStatus = 1) Then Begin FListItem.SubItems.Strings[3] := IntToStr(PingInternal.Reply.RTT); End Else Begin FListItem.SubItems.Strings[3] := 'Down'; End; if FNumFailures > 0 then Begin FListItem.SubItems.Strings[7] := DateTimeToStr(Now); if FListItem.StateIndex = 2 then FListItem.StateIndex := FListItem.StateIndex - FNumFailures Else FListItem.StateIndex := 0; FListItem.SubItems.Strings[5] := IntToStr(StrToInt(FListItem.SubItems.Strings[5])+1); End Else Begin FListItem.SubItems.Strings[6] := DateTimeToStr(Now); FListItem.StateIndex := 2; FListItem.SubItems.Strings[4] := IntToStr(StrToInt(FListItem.SubItems.Strings[4])+1); End; end; procedure TICMP.Execute; begin Try PingExternal := TCustomPing.Create(nil); PingExternal.SetTimeout(1); PingExternal.FStatus := 0; PingInternal := TCustomPing.Create(nil); PingInternal.SetTimeout(1); PingInternal.FStatus := 0; Synchronize(PrepareICMP); DoICMPs; Synchronize(EnterResults); Finally PingInternal.Free; PingExternal.Free; End; end; end. // Now, for the thread creation part. procedure TMainFrm.ActionScanAllExecute(Sender: TObject); Var i: Integer; aThread: TICMP; begin if MonitorList.Items.Count > 0 then for i := 0 to Pred(MonitorList.Items.Count) do begin aThread := TICMP.Create(True); aThread.ListItem := MonitorList.Items.Item[i]; aThread.Start; end; end; -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] TPing, PingThrd1...
Hello, >Are you getting the same result from every public IP address you test, > including non-existent addresses, or just one single IP. I was just testing one internal IP address to a computer that is turned off. The version of TPing ' TPing (c) 1997-2010 F. Piette V6.01 '; After much testing with internal/external, existing/non-existing, addresses/host names, I have determined the timeout value does not have any effect on the results of 'nonexistent' connections. Or really any effect at all. Maybe I am doing something wrong but just setting the timeout does not alter any test. OverbyteIcsIcmp version is 7.01 I see where changing the timeout propagates to the ICMP call. Angus, thanks for your help. Mark -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] TPing, PingThrd1...
> I was just testing one internal IP address to a computer that is > turned off. > Maybe I am doing something wrong but just setting the timeout does > not alter any test. You mean it does not alter in a test to a single IP address. Timeout has always worked for me in numerous applications, on numerous versions of Windows, just check the Trace Route demo application in the zip I mentioned before, where timeout can be set. Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] TPing, PingThrd1...
>> After much testing with internal/external, existing/non-existing, addresses/host names, I have determined the timeout >> value does not have any effect on the results of 'nonexistent' connections. Or really any effect at all. > You mean it does not alter in a test to a single IP address. No, it does not make any difference to any IP address or host name I tested. The demo from the link in an earlier response needed several files that are not included and I did not want to go hunting for them. I need a very simple ping test, threaded. The demo I found works, expect altering the timeout does not change the length of time to wait for a response after the ICMP echo is sent. Mark -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] TPing, PingThrd1...
> *Subject:* Re: [twsocket] TPing, PingThrd1... > Well it seems the timeout has zero effect. > Setting it to any number does not change the result. I was wrong before, the timeout relates to the Windows ICMP blocking request, as does the resulting reply in ms. Are you getting the same result from every public IP address you test, including non-existent addresses, or just one single IP. > The project is named PingThrd. > FPing := TPing.Create(nil); // create in thread context That is a very old project and like all usermade source code, is unsupported. The threaded version has not used TICMP not TPing for 12 years. The last version is at: http://www.magsys.co.uk/download/software/pingthrd.zip but that is also unsupported since ICS V8 now includes a threaded ping. Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] TPing, PingThrd1...
Hello, Well it seems the timeout has zero effect. Setting it to any number does not change the result. Ciao, Mark -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] TPing, PingThrd1...
Hello, > Where did you find that example? Was that some I wrote 10 years ago? >The ICS demo is OverbyteIcsPingTst1, and the ICS V8 version of ping now >includes TPingThread. I got it from the samples on ICS website, I think. The project is named PingThrd. It uses TPingThread. (TPingThread = class(TThread)) The list update line in TPing is: Nov 08, 2010 V6.01 Arno improved final exception handling, more details in OverbyteIcsWndControl.pas (V1.14 comments). > The timeout is simply the maximum period the thread will wait for an ICMP response before exiting. Umm. That does not seem right. Setting timeout calls: procedure TPing.SetTimeout(Value : Integer); begin if Assigned(FIcmp) then FIcmp.Timeout := Value; end; Does not seem thread related. I could be wrong. Thanks for the response. Mark From: zayin [mailto:za...@pdq.net] Sent: Tuesday, September 03, 2013 8:22 AM To: 'twsoc...@elists.org' (twsoc...@elists.org) Subject: TPing, PingThrd1... Hello, Using the PingThrd1 example I set the timeout and it does not make any difference when the no response error message arrives. Received 0 bytes from 10.0.0.9 in 2892 ms I read this on a help page: Timout: Time to wait for response (in milliseconds). Default is 4000, or 4 seconds. Then why was it 2892 milliseconds? I am confused. ;) Then I read this: Time in miliseconds which may elapse between sending and receiving the ICMP packet. So, really the timeout is the maximum time to wait and the response could come much sooner? Does the timeout to the DNSLookup? procedure TPingThread.Execute; var Msg: TagMsg; begin FPing := TPing.Create(nil); // create in thread context FPing.OnDnsLookupDone := FPingDnsLookupDone; FPing.DnsLookup(Addr); FPing.Timeout:=5000; <-ADDED What am I doing wrong? Or am I not understanding the timeout purpose? Thanks, Mark -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] TPing, PingThrd1...
> Using the PingThrd1 example I set the timeout and it does not make > any difference when the no response error message arrives. Where did you find that example? Was that some I wrote 10 years ago? The ICS demo is OverbyteIcsPingTst1, and the ICS V8 version of ping now includes TPingThread. The timeout is simply the maximum period the thread will wait for an ICMP response before exiting. Timeout has nothing to do with DNS look-ups, they have a much longer timeout set by the OS. Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] TPing, PingThrd1...
Hello, Using the PingThrd1 example I set the timeout and it does not make any difference when the no response error message arrives. Received 0 bytes from 10.0.0.9 in 2892 ms I read this on a help page: Timout: Time to wait for response (in milliseconds). Default is 4000, or 4 seconds. Then why was it 2892 milliseconds? I am confused. ;) Then I read this: Time in miliseconds which may elapse between sending and receiving the ICMP packet. So, really the timeout is the maximum time to wait and the response could come much sooner? Does the timeout to the DNSLookup? procedure TPingThread.Execute; var Msg: TagMsg; begin FPing := TPing.Create(nil); // create in thread context FPing.OnDnsLookupDone := FPingDnsLookupDone; FPing.DnsLookup(Addr); FPing.Timeout:=5000; <-ADDED What am I doing wrong? Or am I not understanding the timeout purpose? Thanks, Mark -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be