Checking for internet connection what's wrong here

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Checking for internet connection what's wrong here

Post by shawnblc » Sun May 19, 2013 6:26 pm

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

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: Checking for internet connection what's wrong here

Post by shawnblc » Sun May 19, 2013 7:28 pm

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.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Checking for internet connection what's wrong here

Post by Dixie » Sun May 19, 2013 8:03 pm

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

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: Checking for internet connection what's wrong here

Post by shawnblc » Sun May 19, 2013 8:23 pm

Thanks Dixie, I'll give that a shot.

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: Checking for internet connection what's wrong here

Post by shawnblc » Sun May 19, 2013 10:08 pm

Ok Dixie, this may sound like a dumb question, but how do you clear pending messages when you close or quit a stack?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Checking for internet connection what's wrong here

Post by Simon » Sun May 19, 2013 10:21 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: Checking for internet connection what's wrong here

Post by shawnblc » Sun May 19, 2013 10:34 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Checking for internet connection what's wrong here

Post by Simon » Sun May 19, 2013 11:58 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Checking for internet connection what's wrong here

Post by Dixie » Mon May 20, 2013 7:15 pm

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

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Checking for internet connection what's wrong here

Post by sturgis » Mon May 20, 2013 9:05 pm

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

ludo
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 72
Joined: Mon Dec 03, 2007 6:10 pm

Re: Checking for internet connection what's wrong here

Post by ludo » Wed Aug 14, 2013 9:31 am

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Checking for internet connection what's wrong here

Post by Simon » Wed Aug 14, 2013 10:04 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

ludo
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 72
Joined: Mon Dec 03, 2007 6:10 pm

Re: Checking for internet connection what's wrong here

Post by ludo » Wed Aug 14, 2013 10:18 am

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 ?

Post Reply