Here you can find the source of isLocalPortFree(final int port)
private static boolean isLocalPortFree(final int port)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.ServerSocket; public class Main { private static boolean isLocalPortFree(final int port) { try {// w w w. ja va2s. co m new ServerSocket(port).close(); return true; } catch (final IOException e) { return false; } } }