HttpServer クラスを使用して HTTP サーバーを開発しています。コードは以下のようなものです。
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
*/
}
}
私が望むのは、ハンドラー関数で実際の接続を識別する何か (id 変数またはオブジェクト) を見つけることです。
ハンドラーにブレークポイントを作成し、サーバーをデバッグしてからクライアントを実行すると、httpExchange のコンテンツを確認できます。
接続属性は良い選択だと思います。しかし、httpExchange またはその ID から取得する方法が見つかりません。
何か提案はありますか?