Here you can find the source of isPortAvailable(String host, int port)
public static boolean isPortAvailable(String host, int port)
//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; } }