Page 1 of 1
Checking for internet connection what's wrong here
Posted: Sun May 19, 2013 6:26 pm
by shawnblc
I'd like to be able to check for an internet connection. I have a green image and a red image. Green when connected, red when disconnected. So if my wifi is enabled I'd like to see green, when disabled a red image. Here's my code:
Code: Select all
add 1 to tCount
put URL ("google.com?count=" & tCount) into pURL
get URL pURL
put the result into tResult
if tResult is not empty then
put "disconnected" && tResult into field "fldStatus"
show image "imageRed"
hide image "imageGreen"
return false
else
put "connected" into field "fldStatus"
show image "imageGreen"
hide image "imageRed"
end if
Re: Checking for internet connection what's wrong here
Posted: Sun May 19, 2013 7:28 pm
by shawnblc
Well, if I put the code in the pre openCard it works. The problem is that I have to close the app to get the script to run again when a connection is present. Hmmmm.
Re: Checking for internet connection what's wrong here
Posted: Sun May 19, 2013 8:03 pm
by Dixie
Shawn...
If you want to check your connection every once in a while, you could do something like this...
on openCard
send "checkConn" to this card
end openCard
and in the script of the card...
on checkConn
put "
http://www.google.com" into theURL
put URL theURL into temp
if temp is empty then
put "no connection"
else
put "connected"
end if
beep
send "checkConn" to me in 20 seconds
end CheckConn
Clear the pending messages when you close the card. or quit the stack
Dixie
Re: Checking for internet connection what's wrong here
Posted: Sun May 19, 2013 8:23 pm
by shawnblc
Thanks Dixie, I'll give that a shot.
Re: Checking for internet connection what's wrong here
Posted: Sun May 19, 2013 10:08 pm
by shawnblc
Ok Dixie, this may sound like a dumb question, but how do you clear pending messages when you close or quit a stack?
Re: Checking for internet connection what's wrong here
Posted: Sun May 19, 2013 10:21 pm
by Simon
I recall you have to watch out for pulling up a cached version of the web page so:
Code: Select all
put URL ("http://www.google.com?timestamp=" & the millisecs) into pURL
I'm not completely sure that that is the correct way to write it.
It should get you a fresh page every time and assure you are actually online.
Simon
Re: Checking for internet connection what's wrong here
Posted: Sun May 19, 2013 10:34 pm
by shawnblc
Simon wrote:I recall you have to watch out for pulling up a cached version of the web page so:
Code: Select all
put URL ("http://www.google.com?timestamp=" & the millisecs) into pURL
I'm not completely sure that that is the correct way to write it.
It should get you a fresh page every time and assure you are actually online.
Simon
Thanks Simon. I'll explore that further too. I had the following, but that wouldn't work for me. Maybe I had the parenthesis in the wrong spot. I had...
Code: Select all
put url ("http://www.google.com/?count=") & the seconds into pURL
Re: Checking for internet connection what's wrong here
Posted: Sun May 19, 2013 11:58 pm
by Simon
OK I found it:
Code: Select all
put url ("http://www.google.com/?x=" & the millisec) into pURL
That does it.
You can remove your "get URL pURL" because the "put" above does that.
Simon
Re: Checking for internet connection what's wrong here
Posted: Mon May 20, 2013 7:15 pm
by Dixie
Simon wrote "I recall you have to watch out for pulling up a cached version of the web page so:"... not in what is happening here as the load command is not being used...
Dixie
Re: Checking for internet connection what's wrong here
Posted: Mon May 20, 2013 9:05 pm
by sturgis
The issue sometimes crops up if the url is being cached (where? no clue) so hitting the same url doesn't really do so. Have had it happen to me (not using load) and the easiest answer was like simon suggested, tack on a changing value to the url so a new fetch occurs each time.
I remember this issue from this post:
http://forums.runrev.com/viewtopic.php? ... url#p57137
Dixie wrote:Simon wrote "I recall you have to watch out for pulling up a cached version of the web page so:"... not in what is happening here as the load command is not being used...
Dixie
Re: Checking for internet connection what's wrong here
Posted: Wed Aug 14, 2013 9:31 am
by ludo
Hello,
Strange issue with me :
Code: Select all
function checkConnexion
put ("http://www.google.com/?x=" & the millisec) into pURL
put url (pURL) into pURL
if pURL is empty then
return false
else
return true
end if
end checkConnexion
If the connexion is not active, just few seconds, Livecode return always false even when the connexion come back. And even if i change the url with
Code: Select all
put ("http://www.yahoo.com/?x=" & the millisec) into pURL
MacOSX 10.7 - Livecode 6.1rc2
Re: Checking for internet connection what's wrong here
Posted: Wed Aug 14, 2013 10:04 am
by Simon
Hi ludo,
Go ahead and remove that put url (pURL) into pURL and just use:
put URL("
http://www.google.com/?x=" & the millisec) into pURL
(note the "put URL") save you a step.
Other than that how often are you hitting google? I think you may be polling it? Face it, everybody and their uncle are using it to test connections. Better to use the actual source website you are downloading from (I put up a small text file and check the actual content).
Simon
Re: Checking for internet connection what's wrong here
Posted: Wed Aug 14, 2013 10:18 am
by ludo
Simon wrote:Hi ludo,
Go ahead and remove that put url (pURL) into pURL and just use:
put URL("
http://www.google.com/?x=" & the millisec) into pURL
(note the "put URL") save you a step.
This step is just to debug and saw that the url change every time.
Other than that how often are you hitting google? I think you may be polling it? Face it, everybody and their uncle are using it to test connections. Better to use the actual source website you are downloading from (I put up a small text file and check the actual content).
It could be severals minutes between the check. And even if i change the url to an other domain (like yahoo) it return false ! But if the command put URL() return always empty, revBrowser work ! After quit and reopen Livecode it's work...
Maybe a bug ?