Checking if internet is connected using tsNet?

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
Hi friends,

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?

Thanks for any hints!


Best

Klaus
--
Klaus Major
http://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode

> Am 26.07.2018 um 16:40 schrieb Klaus major-k via use-livecode <[hidden email]>:
>
> Hi friends,
>
> 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?
>
> Thanks for any hints!

Cheese anyone? 8-)

--
Klaus Major
http://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
On 07/27/2018 09:32 AM, Klaus major-k via use-livecode wrote:

>
>> Am 26.07.2018 um 16:40 schrieb Klaus major-k via use-livecode <[hidden email]>:
>>
>> Hi friends,
>>
>> 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?
>>
>> Thanks for any hints!
>
> Cheese anyone? 8-)

Yum. Cheese.
Define "valid"...

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
Hi Mark,

> Am 27.07.2018 um 18:44 schrieb Mark Wieder via use-livecode <[hidden email]>:
>
> On 07/27/2018 09:32 AM, Klaus major-k via use-livecode wrote:
>>> Am 26.07.2018 um 16:40 schrieb Klaus major-k via use-livecode <[hidden email]>:
>>>
>>> Hi friends,
>>>
>>> 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?
>>>
>>> Thanks for any hints!
>> Cheese anyone? 8-)
>
> Yum. Cheese.

I KNEW this would get some attention! :-)

> Define "valid"...

Sorry, I meant if the machine is currently connected to the internet.
And if an URL actually does exist = "valid".

> --
> Mark Wieder
> [hidden email]

Best

Klaus

--
Klaus Major
http://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
On 07/27/2018 09:48 AM, Klaus major-k via use-livecode wrote:

> Sorry, I meant if the machine is currently connected to the internet.
> And if an URL actually does exist = "valid".

So an active ethernet connection won't do the trick.
And a valid address won't work either.
I don't know of any way to validate that an address outside your local
subnet exists other than trying to connect to it.

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
Hi Mark,

> Am 27.07.2018 um 19:11 schrieb Mark Wieder via use-livecode <[hidden email]>:
> On 07/27/2018 09:48 AM, Klaus major-k via use-livecode wrote:
>> Sorry, I meant if the machine is currently connected to the internet.
>> And if an URL actually does exist = "valid".
> So an active ethernet connection won't do the trick.
> And a valid address won't work either.
> I don't know of any way to validate that an address outside your local subnet exists other than trying to connect to it.

too bad, thanks for the clarification!

So back to trying to load GOOGLE and checking for an error...

> --
> Mark Wieder
> [hidden email]

Best

Klaus

--
Klaus Major
http://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
In reply to this post by Clarence Martin via use-livecode
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"

===
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.

BR


On 7/26/18, 4:40 AM, "use-livecode on behalf of Klaus major-k via use-livecode" <[hidden email] on behalf of [hidden email]> 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?

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
In reply to this post by Clarence Martin via use-livecode
Klaus wrote:

 >> Define "valid"...
 >
 > Sorry, I meant if the machine is currently connected to the internet.
 > And if an URL actually does exist = "valid".

Assuming the protocol in question is HTTP/S, a request to a non-existent
resource should return "404" in the error string provided in "the
result".   If "the result" is empty the resource was retrieved as expected.

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
In reply to this post by Clarence Martin via use-livecode
Hi Swami,

> Am 27.07.2018 um 19:48 schrieb Sannyasin Brahmanathaswami via use-livecode <[hidden email]>:
>
> 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" <[hidden email] on behalf of [hidden email]> 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
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
In reply to this post by Clarence Martin via use-livecode
Hi Richard,

> Am 27.07.2018 um 19:53 schrieb Richard Gaskin via use-livecode <[hidden email]>:
>
> Klaus wrote:
> >> Define "valid"...
> >
> > Sorry, I meant if the machine is currently connected to the internet.
> > And if an URL actually does exist = "valid".
> Assuming the protocol in question is HTTP/S,

yes.

> a request to a non-existent resource should return "404" in the error string provided in "the result".  
> If "the result" is empty the resource was retrieved as expected.

I treid with a non-existing url and got:
tsneterr: (6) Could not resolve host: www.ghghgtztztuoouummmb.com

No 404, but it is OK for me!

> --
> Richard Gaskin

Best

Klaus

--
Klaus Major
http://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
In reply to this post by Clarence Martin via use-livecode
And don't forget my telnet technique. Telnet will tell you if there is a basic connection without "actually" connecting with a protocol of any sort. So it doesn't suffer from any of the built in timeouts that web protocols must have to work properly.

Bob S


> On Jul 27, 2018, at 10:53 , Richard Gaskin via use-livecode <[hidden email]> wrote:
>
> Klaus wrote:
>
> >> Define "valid"...
> >
> > Sorry, I meant if the machine is currently connected to the internet.
> > And if an URL actually does exist = "valid".
>
> Assuming the protocol in question is HTTP/S, a request to a non-existent resource should return "404" in the error string provided in "the result".   If "the result" is empty the resource was retrieved as expected.
>
> --
> Richard Gaskin
> Fourth World Systems
> Software Design and Development for the Desktop, Mobile, and the Web


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
In reply to this post by Clarence Martin via use-livecode
On 07/27/2018 10:48 AM, Sannyasin Brahmanathaswami via use-livecode wrote:

>     if  (tResult < 400) then
>        return true
>     else
>        return false
>     end if

I'd be a little wary of that "< 400" result though. You may (or may not)
want to follow redirects, and if you get a 418 you may want a cuppa <g>.

and due to the extra hops involved, I probably wouldn't try for
"https://www.google.com". DNS resolution will add tens to over a hundred
milliseconds to a web command, so if you're going to go that route
instead of opening a socket I'd go straight to "http://8.8.8.8:53".

curl -v --trace-time 8.8.8.8:53
20 milliseconds

curl -v --trace-time www.google.com
50 milliseconds

But otherwise, yes... there is no way of checking for the internet
without connecting to the internet.

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
Well the use case differences are obvious, but to say the obvious

I am connecting with

a) our own server
b) YouTube

that’s it.

AND I want to know if the URL in the app is correct (silly typo in a JSON in the app OR misfiled media on out server...etc), so I would always to get the header of the actual media being called. We can traps errors, send to the MotherShip the URL that failed and fix it... etc.

That different from (Klaus's ?) "am I connected or not"

BR

On 7/27/18, 12:44 PM, "use-livecode on behalf of Mark Wieder via use-livecode" <[hidden email] on behalf of [hidden email]> wrote:

    >     if  (tResult < 400) then
    >        return true
    >     else
    >        return false
    >     end if
   
    I'd be a little wary of that "< 400" result though. You may (or may not)
    want to follow redirects, and if you get a 418 you may want a cuppa <g>.
   
    and due to the extra hops involved, I probably wouldn't try for
    "https://www.google.com". DNS resolution will add tens to over a hundred
    milliseconds to a web command, so if you're going to go that route
    instead of opening a socket I'd go straight to "http://8.8.8.8:53".
   
    curl -v --trace-time 8.8.8.8:53
    20 milliseconds
   
    curl -v --trace-time www.google.com
    50 milliseconds
   
    But otherwise, yes... there is no way of checking for the internet
    without connecting to the internet.

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
In reply to this post by Clarence Martin via use-livecode
Bob...

Wondering if you would post the windows-version of this technique again... or copy it to this forum, ideally?

The dropbox entry I can find is expired.


>  Subject: Re: Checking if internet is connected using tsNet?
>
> And don't forget my telnet technique. Telnet will tell you if there is a basic connection without "actually" connecting with a
> protocol of any sort. So it doesn't suffer from any of the built in timeouts that web protocols must have to work properly.

> Bob S


Douglas Ruisaard
Trilogy Software
(250) 573-3935




_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
A little late to the respond on this but I’d send a HTTP HEAD request. You will get a 200 response back with no data if you have an http connection to the url you specify. You could use your own server to send the request to but it is common to use a well known service such as google to send the HEAD request to also.

The Liveocde lesson at the link below shows how you can send a DELETE request using tsNetCustomSync. You’ll have to modify the script slightly to work for the HEAD request.

http://lessons.livecode.com/m/4071/l/856543-how-to-send-a-custom-http-request-using-the-tsnet-external <http://lessons.livecode.com/m/4071/l/856543-how-to-send-a-custom-http-request-using-the-tsnet-external>

Bob Hall

> On Jul 28, 2018, at 12:42 PM, Douglas Ruisaard via use-livecode <[hidden email]> wrote:
>
> Bob...
>
> Wondering if you would post the windows-version of this technique again... or copy it to this forum, ideally?
>
> The dropbox entry I can find is expired.
>
>
>> Subject: Re: Checking if internet is connected using tsNet?
>>
>> And don't forget my telnet technique. Telnet will tell you if there is a basic connection without "actually" connecting with a
>> protocol of any sort. So it doesn't suffer from any of the built in timeouts that web protocols must have to work properly.
>
>> Bob S
>
>
> Douglas Ruisaard
> Trilogy Software
> (250) 573-3935
>
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
In reply to this post by Clarence Martin via use-livecode
It's simple: Shell this command:

telnet <yourserverorip> <25>

eg:

telnet smtp.gmail.com 25

You should get a response. SMTP servers will respond with information about the SMTP server. Other connections will simply reply that you are connected. If you get nothing, there is nothing listening at that IP on that port.

Another thing you can do is open a socket, then check the openSockets. Pretty much the same thing, but no data is returned. (that I know of)

I open a socket then check the openSockets every second for 5 seconds, exiting upon success. Afterwards I alert the user and give them a chance to remedy the situation and try again, or else bail out.

If I understand this, the first method, telnet, is blocking so you have to wait for a timeout. The second is non blocking, hence the 5 second loop. Usually if my server is available I get an open socket right away. I call this function every time I attempt a connection the the SQL database. Otherwise, if I don't properly close the last connection, I can get these 1 minute delays while the SQL database times out.

Bob S


> On Jul 28, 2018, at 09:42 , Douglas Ruisaard via use-livecode <[hidden email]> wrote:
>
> Bob...
>
> Wondering if you would post the windows-version of this technique again... or copy it to this forum, ideally?
>
> The dropbox entry I can find is expired.


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Checking if internet is connected using tsNet?

Clarence Martin via use-livecode
That should read:

> telnet <yourserverorip> <yourserverportnumber>

Bob S

> On Jul 30, 2018, at 08:29 , Bob Sneidar <[hidden email]> wrote:
>
> It's simple: Shell this command:
>
> telnet <yourserverorip> <25>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode