Mobile Check Bandwidth Function

Sannyasin Brahmanathaswami brahma at hindu.org
Tue Jul 4 19:56:04 CEST 2017


OK I'm back.. sheesh… Spectrum purchase Time Warner Cable for some Ka
bilion dollars and they run our show here now… but it took them four days to figure out that a splice in a wire between our main modem for the enterprise and the router on the street that was  probably filling up with water everytime it rains here (which is frequent this week.)

But it was a good time to be "up and down" on the internet as I had no choice but to focus on my connectivity scripts.  So this does go so far as giving us a bandwidth value, but I think I have a solution for the "reachability" thing..

Using LTE on my iPhone read all this business in Apple's Docs on "reachability" but even apple is using a ping to www.appleiphonecell.com  which returns the word "success". But our problem is

on pingServer
  put url https://www.himalayanacademy.com/ping.txt" into sOneLineStatus # the file contains one word "true"
end pingServer

Is blocking… on the desktop took sometimes 3 minutes (Yeah.. no kidding) for Livecode to step through that line and return "empty") 
on mobile the app will just hang… but the I had this "ahha!" moment where I thought "Duh, Scott Raney solved this 20 years ago" (really been that long?)

one never knows how much one has forgotten… years ago I did preload media and I thought 

"Wait! What about LOAD… URL Status…. these are none blocking"

So with the connection up and down I went about cooking up what I think is a low-level solution. 
disclaimer: I don't know what I'm doing and there is always a better way.

This is a text only library that is put into use on start up… after start up we send
 off

 connectivity_PingServer  in 500 milliseconds 

after the UI is finished loading


Local sPingURL,sServerAttempts # sURLStatusLog

on connectivity_PingServer
  # may have been cached before' but connectivity died so we need to do this first:
# just in case….
   unload URL "https://www.himalayanacademy.com/ping.txt" 
  put 0 into sServerAttempts
   # Logging: put empty into sURLStatusLog
   put "https://www.himalayanacademy.com/ping.txt" into sPingURL
   load url sPingURL
   dispatch "connectivity_UpdateStatus" to me
end connectivity_PingServer

on connectivity_UpdateStatus
   if URLStatus(sPingURL) = "cached" then
      put "true" into sOnLinestatus
      put 0 into sServerAttempts
# that's it nothing more to do…
   else
      put URLStatus(sPingURL)  into tURLStatus
      if (sServerAttempts > 10) and URLStatus(sPingURL)<> "cached" then
         put tURLStatus into sOnLinestatus
         dialog_CustomMsg true,"Offline or Low Bandwidth", 1500      
   
   # keep checking but don't hog the CPU... 
         put 0 into sServerAttempts # start over again
         send connectivity_PingServer to me in 10  seconds
      else
         # Logging
         --       put URLStatus(sPingURL) & cr after sURLStatusLog
         --       put sURLStatusLog
         add 1 to sServerAttempts
          dialog_CustomMsg true,"Connecting", 800     
         send connectivity_UpdateStatus to me in 800 milliseconds
      end if
   end if
end connectivity_UpdateStatus

# Use this in the module so we don't ping the server constantly.

function connectivity_GetStatus
   return sOnLineStatus
end connectivity_GetStatus

This is working on desktop and mobile

Any refinements you wizards can offer will be appreciated. 

I'm off to dig up an old library that Scott Raney had that I believe monitors download progress. and I bet playing around with this you could get a bandwidth value in a very "primitive" way by just downloading a small file and measure the time?

BR






    > On 07/03/2017 09:35 AM, Richard Gaskin via use-livecode wrote:
    >
    >> "reachability"?  Whiskey Tango Foxtrot?  I'd love to hear the
    >> backstory on that name choice.  It has the scent of things like
    >> "srcBic", adopted from the arbitrary choices of neckbeards who
    >> define OS APIs.  Maybe there's an API for iOS called
    >> NSReachabilityChanged.
    >
    > Well, you've got Apple to blame for that one.





More information about the use-livecode mailing list