Here you can find the source of serverIsUp(int port)
public static boolean serverIsUp(int port)
//package com.java2s; //License from project: Open Source License import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static boolean serverIsUp(int port) { try {/*from ww w . j a v a 2 s .co m*/ URL url = new URL("http", "localhost", port, "/"); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setDoInput(true); httpURLConnection.setDoOutput(true); httpURLConnection.setRequestMethod("GET"); httpURLConnection.connect(); OutputStream outputStream = httpURLConnection.getOutputStream(); outputStream.write("".getBytes()); outputStream.close(); httpURLConnection.disconnect(); return true; } catch (Exception e) { return false; } } }