Java HTTP Port Find freePort()

Here you can find the source of freePort()

Description

free Port

License

Apache License

Declaration

public static int freePort() 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 int freePort() throws IOException {
        ServerSocket ss = new ServerSocket(0);
        try {//from  w w  w . j a  v  a 2 s  .c o m
            return ss.getLocalPort();
        } finally {
            ss.close();
        }
    }
}

Related

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