0
I have an application that will send some packages to the server.
I would like to before sending, check if 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.
This may vary if I am using 3G?
Or how best to take this test?
I do not care if I have internet connection, but if the HOST is responding!
As in "This may vary, if I am using 3g?"
– PauloHDSousa
Simply do what you have to do and fix the error. There is no advantage to doing this test every time you need to access your host. He has an obligation to always be available.
– Androiderson
@Paulohdsousa , being the 3g longer, the return time between 3g and Wifi can be different?
– Thiago Luiz Domacoski