Network Rechability

I just cite Apple:


"If your application provides functionality that requires access to a network, it's very important that your code include a customer alert or notification when the network is not available.

The Reachability sample application demonstrates how to use the System Configuration Reachability API to monitor the network state of an iPhone or iPod touch. Use this sample code to learn how to detect the absence of Wi-Fi and Wireless Wide Area Network (WWAN) services so your application knows when it's necessary to produce a network error alert.

Your users will appreciate knowing when an application has no network access — and missing "network alerts" is the third most common reason for applications being returned to developers for modification."

is it currently possible to implement this?

My App will be highly depend ob global hi-score tables and registration online which means it has to use sockets and it would be pretty bad to be rejected because of this!

P.S.: There is no style for the < c i t e > tags

I believe you can test for a network connection with the Socket Library but you can't determine if you have a Wi-Fi or WWAN (i.e. 3g) connection. There are times when you're only allowed to make a connection on Wi-Fi and so we need an API for that.

Tom

I did not saw a way to test with the socket library without trying to reach something which may already be a bad thing to do!

This reminds me on testing if a network connection exists under windows which then triggered the dial up :)

Has anyone implemented a network check of this sort? I was about to submit an app that included Facebook message posting code but held off when I realized the network error handling should be better.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
local http = require("socket.http")
local ltn12 = require("ltn12")
 
--****************************************************************
function check_conn()
--****************************************************************
        local answer={} -- This contains text web page (or other output from server), if it found
        local error="Network OK"
 
        local wawurl="http://www.google.com" -- or other site, of course
        local c,r=http.request{
                url = wawurl,
                sink = ltn12.sink.table(answer)
        }
        if r=="host not found" then
                error=r
        end
        if (r~=200 and r~="host not found") then
                error="HTTP error "..r
        end
        return error
end

Thanks, Mike!

A problem that I see when using http.request is that the application will "hang" until the request transaction is completed.

As an alternative you can use a pure socket connection:

1
2
3
4
5
6
------------------------------
-- Internet check via Socket
------------------------------
if require("socket").connect("google.com", 80) == nil then
        print("No connection")
end
views:1921 update:2011/9/19 9:18:26
corona forums © 2003-2011