我使用 NanoHTTP 库制作了一个小型 HTTP 侦听器,我想将它与 Apache Commons Daemon ( https://commons.apache.org/proper/commons-daemon/index.html ) 一起使用,以便与 procrun 作为 Windows 服务一起安装。我阅读了文档,但我不明白如何在单独的过程中管理起停作业。如何从另一个单独的 Java 进程中停止 NanoHTTPD?
这是我的类扩展 NanoHTTPD:
public class PrintServer extends NanoHTTPD {
private static final int SERVER_PORT=11100;
private static final String MIMEJSON = "application/json";
public PrintServer() throws IOException {
super(SERVER_PORT);
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
log.info("Cinebot PrintServer avviato e in ascolto su porta {}",SERVER_PORT);
}
public static void main(String[] args) {
try {
new PrintServer();
} catch (IOException ioe) {
log.error("Non posso avviare PrintServer", ioe);
}
}
@Override
public Response serve(IHTTPSession session) {
return newFixedLengthResponse(Response.Status.OK, MIMEJSON, null);
}
}