Here you can find the source of isPortOpen(int port)
public static boolean isPortOpen(int port)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; public class Main { public static boolean isPortOpen(InetSocketAddress connectionPoint) { return isPortOpen(connectionPoint, 100); }/* w ww . j a v a 2s. c o m*/ public static boolean isPortOpen(InetSocketAddress connectionPoint, int timeoutMillis) { boolean isOpen; try { Socket socket = new Socket(); socket.connect(connectionPoint, timeoutMillis); try { socket.close(); } catch (IOException e) { } isOpen = true; } catch (IOException e) { isOpen = false; } return isOpen; } public static boolean isPortOpen(int port) { return isPortOpen(new InetSocketAddress("localhost", port)); } }