Here you can find the source of isFreeTCPPort(final int port)
public static boolean isFreeTCPPort(final int port)
//package com.java2s; //License from project: Apache License import java.net.ServerSocket; public class Main { public static boolean isFreeTCPPort(final int port) { try {//from ww w . j av a2s . c om final ServerSocket ss = new ServerSocket(port); ss.setReuseAddress(true); ss.close(); return true; } catch (final Throwable t) { t.printStackTrace(); return false; } } }