Java HTTP Port Find isPortBound(int port)

Here you can find the source of isPortBound(int port)

Description

is Port Bound

License

LGPL

Declaration

public static boolean isPortBound(int port) 

Method Source Code


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

import java.io.IOException;
import java.net.ServerSocket;

public class Main {
    public static boolean isPortBound(int port) {
        try (ServerSocket socket = new ServerSocket(port)) {
            socket.getClass(); /* reference socket to prevent the compiler complaining that is isn't referenced */
            return false;
        } catch (IOException ex) {
            return true;
        }/*from   w w  w.j  a  v a 2 s.c o m*/
    }
}

Related

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