Java HTTP Port Find isPortOnUse(int port)

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

Description

is Port On Use

License

Apache License

Declaration

public static boolean isPortOnUse(int port) 

Method Source Code


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

import java.io.IOException;
import java.net.*;

public class Main {

    public static boolean isPortOnUse(int port) {
        boolean isUse = false;
        ServerSocket serverSocket = null;
        try {//from   w  ww  .j  a v a 2 s  . c om
            serverSocket = new ServerSocket(port);
            isUse = false;
        } catch (IOException e) {
            e.printStackTrace();
            isUse = true;
        } finally {
            if (serverSocket != null) {
                try {
                    serverSocket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return isUse;
    }
}

Related

  1. isPortFree(int portNumber)
  2. isPortFree(String hostName, String port)
  3. isPortFreeClient(String hostName, int portNumber)
  4. isPortInUse(final String host, final Integer port)
  5. isPortInUse(int port)
  6. isPortOpen(int port)
  7. isPortOpen(int port, String host)
  8. isPortOpen(String host, int port)
  9. isPortUsed(final int portNumber, final String host)