Java HTTP Port Find getRandomPort()

Here you can find the source of getRandomPort()

Description

get Random Port

License

Apache License

Declaration

public static int getRandomPort() 

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 getRandomPort() {
        try (ServerSocket s = new ServerSocket(0)) {
            return s.getLocalPort();
        } catch (IOException e) {
            throw new RuntimeException("Can't get random port");
        }/*  ww w.  j av a  2 s.  c o m*/
    }
}

Related

  1. getRandomFreePort()
  2. getRandomFreePort()
  3. getRandomOpenPort()
  4. getRandomPort()
  5. getRandomPort()
  6. getRandomPorts(int n)
  7. getResponse(String name, String host, int port)
  8. getServerPort()
  9. getSupportedConnectionTypes(Map map)