Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect real network availability?

when iPhone connects to a wireless router, and that router is not connected to the internet? i need to display an error message saying "check you internet connection" i tried the Reachability sample code. but no luck, http://developer.apple.com/library/ios/#samplecode/Reachability/Listings/ReadMe_txt.html

when i disable the WIFI in phone it's working fine, i tried the Checking For Internet Connectivity in Objective C sample code "isDataSourceAvailable" even itz not working,can any one help me to fix this issue, really appriciate.

like image 681
Sam Avatar asked Oct 12 '10 07:10

Sam


People also ask

What is network availability monitoring?

Network availability monitoring software is intended to detect, isolate, and assist in the remediation of performance-related issues in a network. Network availability tools are built to scan devices regularly for key performance metrics.

How do I know if my network is good?

The best site to check on your current real speed is Speedtest. This site is run by Ookla, a network performance company. It gives you your download speed, upload speed, and ping to the closest test. The Ookla speedtest is the most popular of all the internet's performance tests.

What makes a network available and reliable?

Network availability is the percentage of time the infrastructure is operational during a given time period. In other words, uptime divided by total in-service time. Network reliability tracks how long the infrastructure is functional without interruption. Reliability is measured using a couple of different equations.


2 Answers

You could do something like this:

+ (BOOL) pingServer
{
    NSURL *url = [NSURL URLWithString:@"http://some-url-that-has-to-work/"];
    NSURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    NSHTTPURLResponse *response = nil;
    [NSURLConnection sendSynchronousRequest:request
        returningResponse:&response error:NULL];
    return (response != nil);
}

This is a synchronous request, so that it will block the current thread. You can do the whole network check in a background thread, so that blocking it won’t matter, or you can send the request asynchronously. Also you might want to set the HTTP method to HEAD, so that you won’t download the whole resource.

like image 193
zoul Avatar answered Oct 05 '22 15:10

zoul


I recommend you do the same as Microsoft does, and to be really wicked, you can even use their servers, since they probably will make sure those are on line for the foreseeable future.

They look up a hostname and then access a very small file on a web server.

See the same question on serverfault (from a non programming perspective of course.)

Basically look up the IP address for a hostname (in that example "dns.msftncsi.com"), then access the URL, for example http://msftncsi.com/ncsi.txt. This can be done with simple socket programming if you like, real HTTP not necessary.

Open a socket to port 80, on the IP you found by looking up the hostname. Send a string to the socket like so:

"GET /msftncsi.com/ncsi.txt HTTP/1.1\nHost: msftncsi.com:80\n\n"

Then wait for something to return. If anything returns, even a single byte, it means you have Internet access.

Or at least access to this server, which in this example is Microsoft.

like image 45
Prof. Falken Avatar answered Oct 05 '22 14:10

Prof. Falken