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

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

Description

Check if a port is being used in the specified host

License

Apache License

Parameter

Parameter Description
host a parameter
port a parameter

Declaration

public static boolean isPortUsing(String host, int port) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

public class Main {
    /**/*from  w  w  w .ja va2  s . c o  m*/
     * Check if a port is being used in the specified host
     *
     * @param host
     * @param port
     * @return
     */
    public static boolean isPortUsing(String host, int port) {
        boolean flag = false;
        try {

            InetAddress theAddress = InetAddress.getByName(host);
            Socket socket = new Socket(theAddress, port);
            flag = true;
        } catch (IOException e) {
            //do nothing
        }
        return flag;
    }
}

Related

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