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

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

Description

is Port Available

License

Open Source License

Declaration

public static boolean isPortAvailable(String host, int port) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.net.Socket;

public class Main {
    public static boolean isPortAvailable(String host, int port) {
        Socket socket = null;//from  w w w .  j a  va  2  s .c o  m
        boolean available = false;
        try {
            socket = new Socket(host, port);
            available = true;
        } catch (IOException e) {
            // no-op
        } finally {
            if (socket != null) {
                try {
                    socket.close();
                } catch (IOException e) {
                    // no-op
                }
            }
        }
        return available;
    }
}

Related

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