Checking internet connection is blocking

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
trevix
Posts: 970
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Checking internet connection is blocking

Post by trevix » Fri Feb 07, 2020 12:09 am

LC 9.6.0 DP2
OSX 10.14.6
Android 7

Trying to find out in a standalone if there is an internet connection, I am doing this on a function:

Code: Select all

  put url "http://www.google.com" into tURL
if tUrl is empty then...no connection
While it works fine on OSX and iOS, on Android it locks the script for up to 30 seconds (I disabled wifi in order to test this).
I tried to add a

Code: Select all

 set the socketTimeoutInterval to 1000 
but apparently things don't change.

Off course, if I enable wifi, everything works fine.

Why is this? How differently can I do it?
Thankyou
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Checking internet connection is blocking

Post by bogs » Fri Feb 07, 2020 10:20 am

Heya Trevix,

You might try giving this lesson a read, it explains the differences between 'put' and 'load' (blocking and non-blocking) url usage.

If you decide to continue to use 'put' instead, I think I'd check the result, instead of whether the variable has information or not. There might be any number of reasons aside from connectivity that would leave the variable empty, the result will tell you why it is empty.

Edited to give you a picture illustrating what I mean, This machine is obviously connected ( I am posting on it ), but duckduckgo doesn't load using Lc 6.5 because of the antiquity of protocol used in 6.5, not because the network is down.
aPic_ConnectedButNotLoaded.png
Just something to think about...
Image

trevix
Posts: 970
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Checking internet connection is blocking

Post by trevix » Fri Feb 07, 2020 10:48 am

Thanks for the help.
I think I solved as you suggested, putting this in the stack script:

Code: Select all

local sConnectionTrue = false

on OpenStack
     if the environment is "development" and  there is a stack "revStandaloneProgress" and the mode of stack "revStandaloneProgress" > 0 then
          exit OpenStack 
     end if
     breakpoint
     put "No connection" into fld "FldResult"
     send "CheckConnection" to me in 100 milliseconds
end OpenStack

command CheckConnection
     put false into sConnectionTrue
     repeat with U = 1 to 10
          if sConnectionTrue  then 
               put  "Connected" into fld "FldResult"
               beep
               exit CheckConnection
          end if
          load URL ("http://www.google.com") with message "UrlReceived"
          wait 500 milliseconds with messages
     end repeat 
     put "No connection found" into fld "FldResult"
end CheckConnection

On UrlReceived pURL, pURLStatus
     if pURLStatus is "cached" then
          put true into sConnectionTrue
          unload url pURL
     else
          put libURLErrorData(pURL) into theError
          set the text of field "FldResult" to "An error occurred:" & cr & theError & "."
     end if
end UrlReceived
Any further suggestions are welcomed.
Trevix
Attachments
CheckInternet.livecode.zip
(2.34 KiB) Downloaded 188 times
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

Post Reply

Return to “Android Deployment”