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

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

Description

is Listening

License

Open Source License

Declaration

public static boolean isListening(String host, int port)
            throws UnknownHostException, IOException 

Method Source Code

//package com.java2s;
/******************************************************************************* 
 * Copyright (c) 2007 Red Hat, Inc. /*w w w .  j  a va2s  . c  o  m*/
 * Distributed under license by Red Hat, Inc. All rights reserved. 
 * This program is made available under the terms of the 
 * Eclipse Public License v1.0 which accompanies this distribution, 
 * and is available at http://www.eclipse.org/legal/epl-v10.html 
 * 
 * Contributors: 
 * Red Hat, Inc. - initial API and implementation 
 ******************************************************************************/

import java.io.IOException;

import java.net.ConnectException;

import java.net.Socket;

import java.net.UnknownHostException;

public class Main {
    public static boolean isListening(String host, int port)
            throws UnknownHostException, IOException {
        Socket socket = null;
        try {
            socket = new Socket(host, port);
            return socket.isConnected();
        } catch (ConnectException e) {
            return false;
        } finally {
            if (socket != null) {
                socket.close();
            }
        }
    }
}

Related

  1. isConnectionAlive(String protocol, String host, int port)
  2. isFreePort(int portNumber)
  3. isFreeTCPPort(final int port)
  4. isHostAvailable(final String host, final int port)
  5. isHostReachable(String host, int port, int connTimeout)
  6. isLivereloadAvailable(int port)
  7. isLocalPortAvailable(final int port)
  8. isLocalPortFree(final int port)
  9. isLocalPortOccupied(int portNum)