我将如何制作 Bukkit 网络服务器?
How would I make a Bukkit webserver?
我正在尝试启动一个允许您在线控制服务器的 bukkit 插件!不过我有一个小错误。我不知道该怎么做。我会为网站编写代码,我只需要代码来处理 http 请求。请帮忙!
我正在尝试制作这样的东西。您可以使用 com.sun
包,它非常有用,但是 @Deprecated
。我是这样做的:
Public class HttpProcessor {
public HttpProcessor(MainClass plug) {
HttpServer server = HttpServer.Create(new InetSocketAddress(9090), 0);
server.createContext("/returnstaticvalue", new RSVhandler());
}
static class RSVhandler implements HttpHandler {
public void handle (HttpExchange h) throws IOException {
h.getResponseHeaders().set("Access-Control-Allow-Origin", "*");
HttpProcessor.writeResponse(h, "The static value");
}
}
public static void writeResponse(HttpExchange httpExchange, String response) throws IOException {
httpExchange.sendResponseHeaders(200, response.length());
OutputStream os = httpExchange.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
我正在尝试启动一个允许您在线控制服务器的 bukkit 插件!不过我有一个小错误。我不知道该怎么做。我会为网站编写代码,我只需要代码来处理 http 请求。请帮忙!
我正在尝试制作这样的东西。您可以使用 com.sun
包,它非常有用,但是 @Deprecated
。我是这样做的:
Public class HttpProcessor {
public HttpProcessor(MainClass plug) {
HttpServer server = HttpServer.Create(new InetSocketAddress(9090), 0);
server.createContext("/returnstaticvalue", new RSVhandler());
}
static class RSVhandler implements HttpHandler {
public void handle (HttpExchange h) throws IOException {
h.getResponseHeaders().set("Access-Control-Allow-Origin", "*");
HttpProcessor.writeResponse(h, "The static value");
}
}
public static void writeResponse(HttpExchange httpExchange, String response) throws IOException {
httpExchange.sendResponseHeaders(200, response.length());
OutputStream os = httpExchange.getResponseBody();
os.write(response.getBytes());
os.close();
}
}