Java HTTP Port Find freePort()

Here you can find the source of freePort()

Description

free Port

License

Apache License

Declaration

public static int freePort() 

Method Source Code


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

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

public class Main {
    public static int freePort() {
        try (ServerSocket socket = new ServerSocket(0)) {
            return socket.getLocalPort();
        } catch (IOException e) {
        }//w ww. j a  v  a2s . c o m
        throw new RuntimeException("could not find freeport on this host");
    }
}

Related

  1. findUnusedPort()
  2. findUnusedPort(int preferredPort)
  3. findUnusedPorts(int numPorts)
  4. freePort()
  5. freePort()
  6. freePort()
  7. freePort()
  8. freePort(int suggestedPort)
  9. get(int port, String applicationRoot, String resource, String path)