Java HTTP Port Find getFreePort()

Here you can find the source of getFreePort()

Description

get Free Port

License

Open Source License

Declaration

public static int getFreePort() throws Exception 

Method Source Code

//package com.java2s;

import java.net.ServerSocket;

public class Main {
    public static int getFreePort() throws Exception {
        ServerSocket serverSocket = new ServerSocket(0);
        int port = serverSocket.getLocalPort();
        serverSocket.close();//from  w w w  .ja  va  2s.  c  o m

        return port;
    }
}

Related

  1. getFreePort()
  2. getFreePort()
  3. getFreePort()
  4. getFreePort()
  5. getFreePort()
  6. getFreePort()
  7. getFreePort()
  8. getFreePort()
  9. getFreePort()