Java Ping pingUrl(final String address)

Here you can find the source of pingUrl(final String address)

Description

ping Url

License

Open Source License

Declaration

public static boolean pingUrl(final String address) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.*;

public class Main {
    public static boolean pingUrl(final String address) {
        try {/*ww  w .  ja va  2  s. co  m*/
            final URL url = new URL("http://" + address);
            final HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
            urlConn.setConnectTimeout(3000);
            final long startTime = System.currentTimeMillis();
            urlConn.connect();
            final long endTime = System.currentTimeMillis();
            if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                System.out.println("Time (ms) : " + (endTime - startTime));
                System.out.println("Ping to " + address + " was success");
                return true;
            }
        } catch (final Exception e1) {
            e1.printStackTrace();
        }
        return false;
    }
}

Related

  1. ping(String ip)
  2. pingHost(String host)
  3. ping(String url, int timeout)
  4. ping(String url, int timeout)
  5. pingHttp(URL url, int retry, int timeout)
  6. pingURL(final String url)
  7. pingUrl(String Url)