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

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

Description

true:already in using false:not using

License

Open Source License

Parameter

Parameter Description
host a parameter
port a parameter

Exception

Parameter Description
UnknownHostException an exception

Declaration

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

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class Main {
    /***//from   w  w  w  .  ja va 2  s  .  c  o  m
     *  true:already in using  false:not using
     * @param host
     * @param port
     * @throws UnknownHostException
     */
    public static boolean isPortUsing(String host, int port) throws UnknownHostException {
        boolean flag = false;
        InetAddress theAddress = InetAddress.getByName(host);
        try {
            Socket socket = new Socket(theAddress, port);
            flag = true;
        } catch (IOException e) {

        }
        return flag;
    }
}

Related

  1. isPortOpen(int port, String host)
  2. isPortOpen(String host, int port)
  3. isPortUsed(final int portNumber, final String host)
  4. isPortUsed(int port)
  5. isPortUsing(String host, int port)
  6. isReachable(final String hostName, int port, int timeout)
  7. isReachableByPing(String host, int port)
  8. isServerListening(String host, int port)
  9. isServerListening(String host, int port)