Here you can find the source of isPortBound(int port)
public static boolean isPortBound(int port)
//package com.java2s; //License from project: LGPL import java.io.IOException; import java.net.ServerSocket; public class Main { public static boolean isPortBound(int port) { try (ServerSocket socket = new ServerSocket(port)) { socket.getClass(); /* reference socket to prevent the compiler complaining that is isn't referenced */ return false; } catch (IOException ex) { return true; }/*from w w w.j a v a 2 s.c o m*/ } }