I'm developing a HTTP server using HttpServer class. The code is like the following.
public static void main(String[] args) throws Exception {
HttpServer server = HttpServer.create(new InetSocketAddress(8989), 0);
server.createContext("/", new MyHandler());
server.setExecutor(null); // creates a default executor
server.start();
}
static class MyHandler implements HttpHandler {
public void handle(HttpExchange httpExchange) throws IOException {
/*
Some code here
*/
}
}
What I want is to find something (an id variable or an object) that identifyies the actual connection in the handler function.
If I make a break-point in the handler, I debug the server, then I run a client, I can see the content of httpExchange:
I think that connection attribute is a good choice. But I can't find how to get it from httpExchange, or its id.
Is there any suggestion?