Connection test

0

I have an application that will send some packages to the server.

I would like before sending, verify that the server is available. And for that, I did the following:

   public static boolean isConnect(){

        boolean isOn = false;
        try{
            final String command = "/system/bin/ping -c 1 "+HOST;
            int wait = Runtime.getRuntime().exec(command).waitFor();
            Log.d(TAG,"wait: "+wait);
            isOn = ( wait == 0);
        }catch (final Exception e){}
        Log.d(TAG,"Connect: "+isOn);
        return isOn;
    }

But in all cases it always returns 1.

According to the documentation:

  

The exit value of the native process being waited on.

Can this vary if I'm using 3G?

Or what is the best way to do this test?

I do not want to know if I have a connection to the internet, but if HOST is responding!

    
asked by anonymous 10.12.2015 / 16:33

1 answer

0

Actually the method works correctly, the problem is that HOST does not accept ping!

    
15.12.2015 / 13:13