Java HTTP Port Find getAvailablePort()

Here you can find the source of getAvailablePort()

Description

get Available Port

License

Open Source License

Declaration

public static int getAvailablePort() 

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 getAvailablePort() {
        int port = -1;
        try {//from   www  .j ava2  s. co  m
            ServerSocket server = new ServerSocket(0);
            port = server.getLocalPort();
            server.close();
        } catch (IOException exception) {
            port = -1;
        }
        return port;
    }
}

Related

  1. getAnonymousPort()
  2. getAvailableListenPort()
  3. getAvailablePort()
  4. getAvailablePort()
  5. getAvailablePort()
  6. getAvailablePort()
  7. getAvailablePort()
  8. getAvailablePort()
  9. getAvailablePort()