Network reachability checking

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Network reachability checking

Post by Jellicle » Sun Mar 27, 2011 9:49 am

Has anyone got the new network reachability function to work in iOS? Contrary to the documentation (in the new iOS release notes that come with LiveCode 4.6) I'm finding that the reachabilityInfo param of the reachabilityChanged command is empty when a network connection is present; the documentation claims that it should be empty when no connection is available.

What are you finding?
14" MacBook Pro
Former LiveCode developer.
Now recovering.

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Contact:

Re: Network reachability checking

Post by endernafi » Fri Feb 07, 2014 1:18 pm

For a long time, I was checking the network availability via a simple
return (url("http://....") is tValidResponse) method.

Unfortunately, that isn't reliable always.
Because iOS has an advanced cache mechanism
and may respond to a subsequent checkConnection call with a false-positive.
That is, even if there isn't an active connection, the above method may result with true.
I've tried pulling the current time from a php script and checking it against the system time of the device;
but that didn't go well, either, at a scenario like:
There's connection, so the response should be Apr 17th, 2014 - 06:02:58.
But since iOS looks at the cache first, the response is, say, Apr 17th, 2014 - 05:28:17.

Clearing the cache is possible and I do it on occasion.
But clearing it each time one checks the connection doesn't seem as a good approach and may break things.


Then, I turned my eyes to the built-in method.
It was stated as experimental in the Livecode User Guide.
But the dictionary doesn't mention about any experimental aspect and User Guide isn't published anymore.
So, I gave it a try and put a simple test stack together:
mobileReachabilityTest.zip
(1.76 KiB) Downloaded 266 times
Here are the gotchas:

* If there is http:// in the server address, then the result is always empty which means no connection.
www.example.com is ok; example.com is fine, too.

* Despite the definition, putting an IP address won't work.
The result is not empty, engine just ignores the command and doesn't fire up any reachabilityChanged messages.

* If the connection is too slow, then the result is empty which means no connection.
Even if there is a connection and safari can open that particular webpage.
Test scenario:
Bad reception in iPhone {Edge} which shares its connection to an iPod {tethering, portable hotspot}.
The stack on iPod reports no connection although it's connected and can open webpages.
This isn't a bad thing after all, with a connection that slow,
one wouldn't want to interact with a server and try to get a content update.
I don't.


Bottomline?
Built-in reachability method is reliable
as long as you don't prepend an http:// to the url
and you don't use an IP address.


Best,

~ Ender
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Network reachability checking

Post by Jellicle » Fri Feb 07, 2014 10:05 pm

Heh Ender, that post of mine was from 2011 :) I'm using the same method - works fine here :)

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Contact:

Re: Network reachability checking

Post by endernafi » Fri Feb 07, 2014 10:20 pm

I was trying to figure out why I couldn't get it work; that's when I stumbled on your post.
Then I've found that http:// is the problem and, I don't know, I just didn't want to open a new thread :)
It seemed more suitable to reply yours.

Best,

~ Ender
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

Post Reply