Here you can find the source of isPortInUse(final String host, final Integer port)
public static final synchronized Boolean isPortInUse(final String host, final Integer port)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.Socket; public class Main { public static final synchronized Boolean isPortInUse(final String host, final Integer port) { Boolean result = false;/* www . j a v a2 s .c om*/ try { (new Socket(host, port)).close(); result = true; } catch (IOException ex) { } return result; } }