Java HTTP Port Find serverIsUp(int port)

Here you can find the source of serverIsUp(int port)

Description

server Is Up

License

Open Source License

Declaration

public static boolean serverIsUp(int port) 

Method Source Code


//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;
        }
    }
}

Related

  1. safePort(final String port)
  2. searchPort(int number, int even, boolean stream)
  3. selectAvailablePort(int preferedPort)
  4. sendCommand(final String command, final int monitorPort)
  5. sendCommand(String host, Integer port, String cmd)
  6. ServerListening(String host, int port)
  7. serverListening(String host, int port)
  8. serverListening(String hostName, int port)
  9. waitForLiveServer(String webContainerHostname, int webContainerPort, int timeoutMin)