Java HTTP Port Find findFreePort()

Here you can find the source of findFreePort()

Description

find Free Port

License

Open Source License

Declaration

public static int findFreePort() throws Exception 

Method Source Code


//package com.java2s;
import java.net.ServerSocket;

public class Main {
    public static int findFreePort() throws Exception {
        int port;
        ServerSocket socket = new ServerSocket(0);
        port = socket.getLocalPort();//from   w  ww. j a v a  2s  .  co  m
        socket.close();
        return port;
    }
}

Related

  1. findAvailablePort(int minPort, int maxPort)
  2. findAvailablePort(int port)
  3. findAvailablePort(int port)
  4. findAvailablePort(String hostname, int startPort, int endPort)
  5. findAvailablePorts(int n)
  6. findFreePort()
  7. findFreePort()
  8. findFreePort()
  9. findFreePort()