Here you can find the source of isAvailablePort(int port)
public static boolean isAvailablePort(int port)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.*; public class Main { public static boolean isAvailablePort(int port) { ServerSocket ss = null;// w w w .java 2 s . c o m try { ss = new ServerSocket(port); ss.bind(null); return true; } catch (IOException e) { return false; } finally { if (ss != null) { try { ss.close(); } catch (IOException e) { } } } } }