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

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

Description

Is the specified port available?

License

Apache License

Declaration

public static boolean isPortAvailable(String host, int port) 

Method Source Code

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

import java.io.IOException;

import java.net.Socket;

public class Main {
    /**//from   ww  w.jav a  2 s .  c  om
     * Is the specified port available?
     * 
     * Note that this will be true at the time the method run,
     * but may be false a couple of milliseconds after...
     */
    public static boolean isPortAvailable(String host, int port) {
        try {
            (new Socket(host, port)).close();
            return true;
        } catch (IOException e) {
            return false;
        }
    }
}

Related

  1. isPortAvailable(int port)
  2. isPortAvailable(int port)
  3. isPortAvailable(String host, int port)
  4. isPortAvailable(String host, int port)
  5. isPortAvailable(String host, int port)
  6. isPortAvailable(String host, int port)
  7. isPortAvailable(String hostname, int port)
  8. isPortAvailable(String hostname, int port)
  9. isPortAvailable(String hostName, int port)