Java HTTP Port Find findFreePort()

Here you can find the source of findFreePort()

Description

find Free Port

License

Apache License

Declaration

public static ServerSocket findFreePort() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;

public class Main {
    public static ServerSocket findFreePort() {
        ServerSocket server = null;
        try {/*from w  w w.  j a  v a2  s .c  om*/
            server = new ServerSocket(0, 1000, InetAddress.getLocalHost());
            server.setReuseAddress(true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return server;
    }
}

Related

  1. findFreePort()
  2. findFreePort()
  3. findFreePort()
  4. findFreePort()
  5. findFreePort()
  6. findFreePort()
  7. findFreePort()
  8. findFreePort()
  9. findFreePort(int start, int len)