4

I am working on a project that needs to test some feature of android and mobile networks. one of them is to check Reliability of the internet connection to do that i should first check the Internet connection itself and then check the Reliability

Is there any Algorithm or library to find out the Reliability of Internet Connection

Martin
  • 429
  • 3
  • 18
  • i think this existing question can partially answer your problem http://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-times-out – Bhavesh Aug 17 '16 at 10:41
  • what do you mean by reliability??? i suppose you can check internet connection regularly using basic socket connection. – Bhavesh Aug 17 '16 at 10:44
  • Thank sir but as i said at first i test the internet connection but then i need to test internet connection reliability Like : is the connection reliable or not. – Martin Aug 17 '16 at 10:45
  • Reliability means trust on internet connection not to just check the internet connection Like if a connection connects and disconnect every 5 min its not reliable! – Martin Aug 17 '16 at 10:48
  • Keep checking internet connection -> create your own data and use that to define reliability. I think this should work for you. I am not sure if there are any other ways to do so. – Bhavesh Aug 17 '16 at 10:55
  • Thanks for your comment, I am sure this algorithm does not solve my problem. I am looking for some Standard solution/ – Martin Aug 17 '16 at 11:02
  • We solved this by implementing a socket connection to a backend server with a heartbeat protocol. Do you have a backend server available? – mach Aug 18 '16 at 06:14
  • @mach yes we do have a backend server! What is heartbeat protocol and how should id solve this problem – Martin Aug 21 '16 at 03:53

1 Answers1

0

Perhaps you can send a request to a known site to check if the internet connection is stable enough to get back with the response in given time.

public boolean checkInternet(){
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnected())
                try {
                        URL url = new URL("http://www.google.com");
                        HttpURLConnection urlc = (HttpURLConnection) url
                                                 .openConnection();
                        urlc.setConnectTimeout(3000);
                        urlc.connect();
                        if (urlc.getResponseCode() == 200) {
                                // Means response is available within 3 seconds
                                // So, return true or do something else.
                                return true;
                        }
                } catch (MalformedURLException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        return false;
}
fluffyBatman
  • 6,524
  • 3
  • 24
  • 25
  • If i set the time out to 5000 it will check the connection again within 5 second or i need to create a loop for that? – Martin Aug 17 '16 at 12:09
  • You'll need to call this method whenever you need to check internet strength. You can always pass the timeout as method param if you need to call the method with different timeouts. – fluffyBatman Aug 17 '16 at 13:07