Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inetctls - Still executing last request

bs6600

Programmer
Sep 23, 2005
54
GB
Is there anything new about this.?
I want to monitor my router's performance so want to leave my code running unattended for some time.
I just repeatedly get a url = connected (or false or null = not connected) and it mostly works but I get a halt occasionally with 'Still executing last request' which stops my monitor so is no good. This happens randomly perhaps mostly when there is no connection but not always.

Question.
Is there a better way to check that I still have an internet connection? (or is there a fix for the way I do it?)

My code is
.oInet=CREATEOBJECT("inetctls.inet")
.oInet.protocol = 4 && Set to HTTP
ix = .oInet.openurl("https://www.rotary-ribi.org/clubs/page.php?PgID=846256&ClubID=27", 0)
.oinet=NULL



Sorry this is an old problem but I can't get any of previous suggestions to work
 
it mostly works but I get a halt occasionally with 'Still executing last request' which stops my monitor
Isn't that simply a problem of catching that error and continuing? Knowing you're currently offline, obviously. Why does it crash your monitor application?

Besides that, all in all you can never really know you're online or offline, even though such API functions and Browser flags exist. If you read discussions they always boil down to this:
You may get reliable information about being offline, but you may get false positives on being online. So you never can be sure openurl does not error, even if such flags of the OS or browser tell you, you're online.

Which means getting a URL request done is prove of a online connection, which you take as an online test or current status. Might always also be the case the server isn't reachable/offline, but you can check lots of URLs or more reliable URLs like google.com.

Are you saying inetctls.inet throws exceptions that neiither TRY CATCH nor an ON ERROR routine would catch but end the process? Then make your test requests with something else, like Msxml2.ServerXMLHTTP?
 
Last edited:
Is your intent to just check periodically if your internet connection is alive?
Not sure what you're trying to achieve.
 
It's simple to reproduce the error you report by using a nonexistant URL, like this:

Code:
nRequestfails = 0
oInet=Createobject("inetctls.inet")
oInet.protocol = 4 && Set to HTTP
Try
   ix = oInet.openurl("https://notexisting.url", 0)
   nRequestfails = 0
Catch
   nRequestfails = nRequestfails + 1
Endtry

oInet=Null


* legacy code using ON ERROR handling
nRequestfails = 0
plRequestFailed = .F.
On Error plRequestFails = .T.
oInet=Createobject("inetctls.inet")
oInet.protocol = 4 && Set to HTTP
ix = oInet.openurl("https://notexisting.url", 0)
If plRequestFailed
   nRequestfails = nRequestfails + 1
Else
   nRequestfails = 0
EndIf
On Error
oInet=Null

There's nothing special about this error, except it's an OLE error, but you can catch it one or the other way and it doesn't crash your process. So it seems to me you don't know about error handling.

This demo code sketches a solution to determine your online status by counting failed requests. As the example shows you can get the error when you request a URL that doesn't exist, so the error does not necessary tell you, you're offline. But if you try with several URLs, you'll surely reset the counter to 0 at some point. I'd define a thershold of failed requests to switch to offline status. It will then not even matter whether you can detect that because even when you are sure by say 5 failed requests, what would you do to get online again? All you can do is try further requests. One per minute, or whatever you do. Until one request gets a response again.
 
Just to round this up, the idea of checking internet connectivity with a request is implemented all over the place in many ways.

1) How Windows decides about your Internet connection, described by Raymond Chen:

2) InternetCheckConnectionA: https://learn.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetcheckconnectiona
But see Remarks:

Remarks​


InternetCheckConnection is deprecated. InternetCheckConnection does not work in environments that use a web proxy server to access the Internet.
Besides the point of deprecation it takes a URL to test as parameter, so the test like in 1) is based on getting a request done.

3. InternetGetConnectedState: https://learn.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetgetconnectedstate
Besides the note it's not recommended and instead something else (4) should be used, the remarks describe that it's not a general indicator for internet connectivity:

Remarks​


A return value of TRUE from InternetGetConnectedState indicates that at least one connection to the Internet is available. It does not guarantee that a connection to a specific host can be established
4. GetConnectivity: https://learn.microsoft.com/en-us/w...etlistmgr-inetworklistmanager-getconnectivity
Returns a pointer on a structure that has several logical flags indicating what type of network connectivity exists, including Internet over ipc4 or ipv6.

It seems the most appropriate functionality, I personally doubt it's free of the problem I outlined in my earlier post: false positives or false negatives.

5. The same problem in the perspective of JS running in a browser is discussed here: https://stackoverflow.com/questions/189430/detect-if-the-internet-connection-is-offline
Browser seem to provide a simple logical flag window.navigator online. If you read the discussion you see true may not mean an internet connection, just connection "to some network at best".

All in all seeing the code you use, I don't need to convince you making a request and getting a response is a valid approach, the only downside of that is if you don't get a response it desn't necessarily mean your internet connection is down, it could just be the server is down - or the URL is not valid.

There are a gazillion ways to make a http request and using inetctls.inet is surely not the first I have on my mind. So in regard of the aspect of your question whether there is anything newer. inetctls.inet is surely not the latest at all. Without using OLE at all you could make a request by URLDownloadToFile: https://learn.microsoft.com/en-us/p.../ie-developer/platform-apis/ms775123(v=vs.85)
With "is there something new on this?" You may refer to an old thrad, but I don't find one you posted about it.

As siad, error handling will catch the error of inetctls.inet and if you experience your monitoring application stops working it seems you don't know about error handling, if that trips you already. But I would replace that method by anything else anyway, the simplest base could really be URLDownloadToFile.

I already mentioned Msxml2.ServerXMLHTTP which has the advantage over inetctls.ine that it needs no installation in setups. It has one option URLDownloadToFile does not have: You cannot only make a GET request that gets the full response, you can also make a HEAD request that only needs to receive the head of the get request. On the other side, as mentioned in 1) the content of the response can be used to verify you don't just get a response, but it delivers the expected content.

There's one more even simpler way: ping. Not pinging a LAN IP address, obviously, but pinging some internet server. Anyway, I'd perhaps research a bit more to see whether URLDownloadToFile could give you false positives by downloading cached content whereas the actual internet connection is down, but otherwise it seems the best candidate considering the additional validation of the content of the downoaded file to be as expected. It requires to be able to rely on such a static content, though. The two Microsoft txt URLs still work, but are http URLs. Request them over https and a browse will show you a possible security risk. And I wonder whether the short content the two texts have really give a good insight of what went wrong, if you get some crumbled other text instead.

Anyway, you may stick to your code, just add error handling and you're done.
 
Last edited:
One more idea about which URLs to test: Almost any website has a robots.txt file with rules for (good and compliant) web crawlers. So if you want to go for more than ping and make full requests pulling verifiable texts, that's a good idea, as robots.txt files will mostly be static.

Plus your EXE itself, though you don't crawl the content of a whole or partial website would be welcome to read robots.txt files, there's nothing to fear about requesting these files even for the purpose of testing your internet connectivity.
 
Is your intent to just check periodically if your internet connection is alive?
Not sure what you're trying to achieve.
Thanks Scott.
Yes I'm getting a lot of dropouts on all my devices and my IP provider is not being helpful so I want to gather some evidence.

I planned to run my monitor program for say 24 hours unattended and log the ups and downs.
 
Thanks Chriss,

Apart from the last line what you say is a bit over my head at the moment.

I only have VFP as my basic tool and invoking some of the things you mention is beyond my knowledge level,.

I'll brush up on error handling.
 
I listed the different options available so you can see there's far more than just using inetctls.inet.

I actually wonder where you got that from, and as you asked "Is there anything new about this?" and I didn't find an older thread by you about it, I double wonder about that and why you even use it. If you look for threads about http requests, they are usually about a httprequest class. And ping or URLDownLoadToFile are even simpler commands or API functions doing what you intend to do.

I now get your code is not old and you come across a problem recently after it worked for weeks, months, years, perhaps. you're intending to prove to your ISP how oftern your internet connectivity breaks.

Well, if you run something that makes inter requests to detect you're offline, then the firt thing you should try is to create a case that's detected as being offline. Intentionally turning off your Wifi, for example, or unplugging a cable. And then you get that error message. The standard error handling of VFP is showing the error in a messagebox. If code is unattended that ends monitoring, of course. It's the main case you programmed for, why didn't you test it?

Anyway, error handling is as easy as putting the one line of code you expect to break in a TRY..CATCH..ENDTRY structure, which technically is as easy to understand as an IF..ELSE..ENDIFF construct. Or telling VFP what to do in case of an error, instead of just displaying a message that's nonsense for any unattended process. The simplest handling is what I showed you with the line On Error plRequestFailed = .T.

Which means any error, whatever it is, would cause plRequestFailed to become .T. And there is only one line in your code from which you expect an error to happen in the case of the broken internet connection: ix = oInet.openurl("https://notexisting.url", 0)

So just threee things to do,
1. initialize plRequestFailed = .F. before the openurl call
2. tell VFP to set plRequestFailed = .T. in case of an error with On Error plRequestFailed = .T.
3. Check plRequestFailed after the openurlcall.

It covers two subjectives: 1. detecting problems and 2. not showing an error message and waiting for a user to see and confirm being notified.

You'll have to have such error handling no matter what exactly you'll use, that's the core aspect of telling whether your connectivity is broken or works.
 
Did you solve your monitoring? We like to get a feedback whether a recommendation worked or not for the knowledgebase characteristic of tek-tips.

If you didn't yet solve it, how about using something already existing? For example there's a reddit discussion about such monitoring apps at where you find browser extensions, apps and other software.

Other developer tools for network monitoring are Wireshark (most comprehensive), fiddler (spcialised on http = internet traffic and acting as a proxy) and firebug - specialised on http within firefox. See a discussion about them in https://stackoverflow.com/questions/4263116/wireshark-vs-firebug-vs-fiddler-pros-and-cons and I'm sure there's more like that, but that's already a sufficient variety to pick from.

And then one last detail about all this: If your connectivity is broken there are several details that can contribute. Your WiFi could need a reset, the DNS server provided by your ISP might be down (for you) which leads to unresolved requests while your internet connection actually still is healthy. Using Googles DNS services at the static ip address 8.8.8.8 could help with that, you'd set this up in your network adapter configuration. And then your router might work fine again after a reset or the internet connection comes back after restarting your computer/laptop.

I personally sometimes have the situation my phone is still in Wifi connected and apps using internet work, while my laptop has become offline and then sometimes resetting WiFi or restarting helps. I never had the inverse - my laptop online, my phone offline - but whenever you have contradicting informations from two devices that's an obvious sign the problem is something on your side. Not saying this is your situation - and that's why you want to find out more by monitoring. But then I think already existing solutions are better usable, especially as monitoring directly on the router wouldn't work with a VFP exe, as such hardware at best has a Linux based OS, if not something propretary that's not a usual OS. If you want to monitor all your devices that asks for solutions running on them and VFP can only cover Windows OS based devices.
 
Last edited:

Part and Inventory Search

Sponsor

Back
Top