Here you can find the source of waitForPort(String host, int port)
public static boolean waitForPort(String host, int port)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.Socket; public class Main { private static final int RETRIES = 10; private static final int WAIT_TIME_MS = 2000; public static boolean waitForPort(String host, int port) { for (int i = 0; i < RETRIES; i++) { if (isPortAvailable(host, port)) return true; try { Thread.sleep(WAIT_TIME_MS); } catch (InterruptedException e) { // no-op }/* ww w. j av a 2 s. c o m*/ } return false; } public static boolean isPortAvailable(String host, int port) { Socket socket = null; boolean available = false; try { socket = new Socket(host, port); available = true; } catch (IOException e) { // no-op } finally { if (socket != null) { try { socket.close(); } catch (IOException e) { // no-op } } } return available; } }