Java HTTP Port Find findAvailablePort()

Here you can find the source of findAvailablePort()

Description

find Available Port

License

Open Source License

Declaration

public static int findAvailablePort() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static int findAvailablePort() {
        try (ServerSocket socket = new ServerSocket(0)) {
            return socket.getLocalPort();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }//w  w w .  j  a va2s.co  m
    }
}

Related

  1. createUnresolved(String host, int port)
  2. doSend(String command, String server, String port)
  3. executeHttpCommand(String host, int port, String request, String charset)
  4. exportResource(Class fromClass, String resourceName, String exportPath)
  5. findAvailablePort()
  6. findAvailablePort()
  7. findAvailablePort()
  8. findAvailablePort()
  9. findAvailablePort(int min, int max)