I am trying to create an http server using JDK's com.sun.net.httpserver. I am able to run the server with certain endpoints successfully. And it return some random ephemeral port ranging from 0 to 65536.
HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
I was going through the documentation but I couldn't see a way to specify some range instead of specific port. Is there any way passing range can be achieved?
One hack to the solution is try for all ports in range and see whichever works as specified in the solution - How to find an available port?