Q:

how to check if server is down in android

I want to send a string to a server at every 3 min. I am sending data from android phone to server using following code :
String stringDatatoSend="Hii server";
HttpEntity entity;
HttpClient client = new DefaultHttpClient();
String url ="http://some IP/android/insert.php";
HttpPost request = new HttpPost(url);
StringEntity se = new StringEntity(stringDatatoSend);
se.setContentEncoding("UTF-8");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
entity = se;
request.setEntity(entity);
HttpResponse response = client.execute(request);
entity = response.getEntity();

But if the server is down data is lost because data is send irrespective of any acknowledgement. how can I check if
the server is alive before the data is send to avoid data loss.I have tried following code but it always returns false.
public boolean isConnectedToServer() {
    try {
        if(InetAddress.getByName("http://some IP/android/insert.php").isReachable(50000)) {
            return true;
        } else {
            return false;
        }
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        return false;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        return false;
    }
}

I have also got these two options :
netAddress address = InetAddress.getByName(HOST_NAME);
boolean  reachable = address.isReachable(timeout);

and by using runtime:
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("ping www.google.com");

what should be the host name ip or address.

A:

You need to send data again after every 3 minutes, You can't actually control if server is responding or not, or your device's network performance. But you can control the calls you are making to the server. If you are not getting data acknowledgement it means your data is not yet received by the server and you need to send it again. Just check the acknowledgement of data receive from server and then send/resend data.

