//check if the previous URI is a shutdown command shutdown = request.getUri().equals(SHUTDOWN_COMMAND); } catch (Exception e) { e.printStackTrace(); continue; } } }
await 方法以創建一個 ServerSocket 實例開始,然后進入一個 while 的循環。 serverSocket = new ServerSocket( port, 1, InetAddress.getByName("127.0.0.1")); ... // Loop waiting for a request while (!shutdown) { ... }
最后,await 方法關閉 Socket ,呼叫 Request 的 getUri 方法來檢查 HTTP 請求的地址是否是一個停止命令。假如是,則 shutdown 變量被設置為 true ,程序退出 while 循環: // Close the socket socket.close(); //check if the previous URI is a shutdown command shutdown = request.getUri().equals(SHUTDOWN_COMMAND);