Here you can find the source of waitForSocket(int port)
public static void waitForSocket(int port)
//package com.java2s; import java.io.IOException; import java.net.Socket; public class Main { public static void waitForSocket(int port) { long notAfter = System.currentTimeMillis() + 5000; for (; System.currentTimeMillis() < notAfter;) { Socket sock = null;// ww w . j a v a 2s .c o m try { Thread.sleep(100); sock = new Socket("127.0.0.1", port); break; } catch (Exception ex) { // Ignored. } finally { if (sock != null) { try { sock.close(); } catch (IOException e) { // Ignore this as well. } } } } } }