Java HTTP Port Find getUnusedPort()

Here you can find the source of getUnusedPort()

Description

Get a port that isn't currently used.

License

Open Source License

Declaration

public static int getUnusedPort() throws IOException 

Method Source Code


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

public class Main {
    /**//w ww .  j  a  v a 2s . c o m
     * Get a port that isn't currently used. 
     */
    public static int getUnusedPort() throws IOException {
        ServerSocket s = new ServerSocket(0);
        int port = s.getLocalPort();
        s.close();
        return port;
    }
}

Related

  1. getRandomPorts(int n)
  2. getResponse(String name, String host, int port)
  3. getServerPort()
  4. getSupportedConnectionTypes(Map map)
  5. getSupportedEntityTypes()
  6. getUnusedPort(final int start)
  7. getUnusedPort(int startPort)
  8. getUnusedPorts(final int count, final int start)
  9. getValidZooKeeperPort()