Java HTTP Port Find isConnectionAlive(String protocol, String host, int port)

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

Description

is Connection Alive

License

Apache License

Declaration

public static boolean isConnectionAlive(String protocol, String host, int port) 

Method Source Code

//package com.java2s;
/**//from   ww  w.  j a va  2  s  .c  o m
 * Phresco Commons
 *
 * Copyright (C) 1999-2014 Photon Infotech Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static boolean isConnectionAlive(String protocol, String host, int port) {
        boolean isAlive = true;
        try {
            URL url = new URL(protocol, host, port, "");
            URLConnection connection = url.openConnection();
            connection.connect();
        } catch (Exception e) {
            isAlive = false;
        }
        return isAlive;
    }
}

Related

  1. isAvailablePort(int port)
  2. isBindable(int port)
  3. isBindedPort(String host, int port)
  4. isBound(int port)
  5. isBound(int port)
  6. isFreePort(int portNumber)
  7. isFreeTCPPort(final int port)
  8. isHostAvailable(final String host, final int port)
  9. isHostReachable(String host, int port, int connTimeout)