Java Socket Port waitForSocket(int port)

Here you can find the source of waitForSocket(int port)

Description

wait For Socket

License

Open Source License

Declaration

public static void waitForSocket(int port) 

Method Source Code


//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.
                    }
                }
            }
        }
    }
}

Related

  1. getRandomPortServerSocket()
  2. getServerSocket(int i_Port)
  3. isValidSocket(String host, int port)
  4. releasePort(ServerSocket ss)
  5. removeSocket(String host, int port)