Java HTTP Port Find findFreePort()

Here you can find the source of findFreePort()

Description

find Free Port

License

Apache License

Declaration

public static synchronized int findFreePort() throws IOException 

Method Source Code

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

import java.io.IOException;

import java.net.ServerSocket;

public class Main {
    public static synchronized int findFreePort() throws IOException {
        try (ServerSocket socket = new ServerSocket(0)) {
            return socket.getLocalPort();
        }/*from ww  w  .j av  a 2 s.  c  o m*/
    }
}

Related

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