Java HTTP Port Find isServing(String host, int port)

Here you can find the source of isServing(String host, int port)

Description

is Serving

License

Apache License

Parameter

Parameter Description
host the host to try to connect to
port the port to try to connect on

Return

whether a socket connection can be made to the given host on the given port

Declaration

public static boolean isServing(String host, int port) 

Method Source Code

//package com.java2s;
/*//w w  w  . j a v  a  2  s  .co m
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the ?License??). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

import java.io.IOException;

import java.net.Socket;

public class Main {
    /**
     * @param host the host to try to connect to
     * @param port the port to try to connect on
     * @return whether a socket connection can be made to the given host on the given port
     */
    public static boolean isServing(String host, int port) {
        if (port < 0) {
            return false;
        }
        try {
            Socket socket = new Socket(host, port);
            socket.close();
            return true;
        } catch (IOException e) {
            return false;
        }
    }
}

Related

  1. isReachable(final String hostName, int port, int timeout)
  2. isReachableByPing(String host, int port)
  3. isServerListening(String host, int port)
  4. isServerListening(String host, int port)
  5. isServerPortFree(int port)
  6. isStart(String host, int port)
  7. isStart0(String host, int port)
  8. issueHttpRequest(String methodName, int[] rc, String host, String port, String path)
  9. isTcpPortOpen(int port)