Java HTTP Port Find isPortOpen(int port)

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

Description

is Port Open

License

Apache License

Declaration

public static boolean isPortOpen(int port) 

Method Source Code


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

import java.io.IOException;

import java.net.InetSocketAddress;

import java.net.Socket;

public class Main {
    public static boolean isPortOpen(InetSocketAddress connectionPoint) {
        return isPortOpen(connectionPoint, 100);
    }/* w ww  .  j a v  a  2s. c  o m*/

    public static boolean isPortOpen(InetSocketAddress connectionPoint, int timeoutMillis) {

        boolean isOpen;

        try {
            Socket socket = new Socket();
            socket.connect(connectionPoint, timeoutMillis);
            try {
                socket.close();
            } catch (IOException e) {

            }
            isOpen = true;
        } catch (IOException e) {
            isOpen = false;
        }

        return isOpen;
    }

    public static boolean isPortOpen(int port) {
        return isPortOpen(new InetSocketAddress("localhost", port));
    }
}

Related

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