Here you can find the source of isActivePort(int port)
public static boolean isActivePort(int port)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.ConnectException; import java.net.InetAddress; import java.net.Socket; public class Main { public static boolean isActivePort(int port) { Socket socket = null;/*from w w w .jav a 2 s.c om*/ boolean var3; try { InetAddress localAddress = InetAddress.getLocalHost(); socket = new Socket(localAddress, port); return true; } catch (ConnectException var20) { var3 = false; } catch (IOException var21) { return true; } finally { if (null != socket && socket.isConnected()) { try { socket.close(); } catch (IOException var18) { ; } catch (Exception var19) { ; } } } return var3; } }