Checking if internet is connected using tsNet?

Klaus major-k klaus at major-k.de
Fri Jul 27 19:54:54 CEST 2018


Hi Swami,

> Am 27.07.2018 um 19:48 schrieb Sannyasin Brahmanathaswami via use-livecode <use-livecode at lists.runrev.com>:
> 
> I just went through  this in my app. Like Mark said, you do need to connect to "something"
> I put a "ping.txt" on the server. It has one word "true".  Apple does the same thing. Though they call it something else  "serviceAvailable" or something like that and it has one word in it "available"

OK, that will work for your own server, but not in general.

> ===
> But with TSNet you can just "ping" for the url you are trying  get. By using tsNetHeadSync, you don't have to down load the whole file. It will return headers.
> 
> It is very fast, so with so much music and online links books  and youTube videos, with users going in and out of wi-fi, they forgot their phone on airport mode etc.  There is no way of knowing the user context. 
> 
> So I just implemented this in one of my main backscripts and call it *every* time when try to connect. Turn out the was easy them expected. I only take a few millisecond to get status. Charles did say that tsNetHeadSync was probably the best way to go.
> 
> =========
> function checkURLAvailable pSelectedURL     
> put  tsNetHeadSync(pSelectedURL, tSentHeaders, tResult, tBytes)  into tHeaders  # into tHeaders
> 
>   ## get url pSelectedURL
>   if  (tResult < 400) then
>      return true
>   else
>      internetConnectionDown
>      return false
>   end if
> end checkURLAvailable
> 
> command internetConnectionDown
>   dialog_CustomMsg "Offline or Low Bandwidth"
>   exit top
> end internetConnectionDown
> ========
> 
> If you don't have 
> 
> a) a ping 
> b) you want test without a URL
> 
> Just use  "https://www.google.com"
> 
> function checkURLAvailable "https://www.google.com"
> 
> put  tsNetHeadSync(pSelectedURL, tSentHeaders, tResult, tBytes)  into tHeaders  
> 
>   ## get url pSelectedURL header
> 
>   if  (tResult < 400) then
>      return true
>   else
>      return false
>   end if
> end checkURLAvailable
> 
> if Google down, so is the whole internet. (smile)
> 
> Almond cheese, please.

:-D

Cool, thanks a lot for thi info!
Please tell Mark W. about it, too! 8-)

> BR
> 
> On 7/26/18, 4:40 AM, "use-livecode on behalf of Klaus major-k via use-livecode" <use-livecode-bounces at lists.runrev.com on behalf of use-livecode at lists.runrev.com> wrote:
> 
>    can we possibly "mis-"use tsNet somehow to check if the 
>    current machine has a valid internet connection? 
>    And to check if a given URL is valid?

Best

Klaus

--
Klaus Major
http://www.major-k.de
klaus at major-k.de




More information about the use-livecode mailing list