I am trying to make a simple HTTP server that streams data to users. I would like the server listener to block main threads execution (take over the main thread):
public static void main(String [] args) throws Throwable {
HttpServer server = HttpServer.create(new InetSocketAddress(80), 0);
// The handler for connections
server.createContext("/test", new MyHandler());
// This is probably what needs tweaking
server.setExecutor(null);
// The start should block
System.out.println("Server started at 0.0.0.0:80.");
server.start();
System.out.println("Server terminated without errors.");
}
The each connection will receive endless stream of data, so they need to be started in separate threads once they connect to the listening socket.