I want NanoHTTPD to process one request at a time. Is there a way to achieve it?
All other requests made at the same time should either wait or be dropped.
Here's my NanoHTTPD server:
package com.example;
import java.io.IOException;
import org.nanohttpd.NanoHTTPD;
import java.util.concurrent.TimeUnit;
public class App extends NanoHTTPD {
public App() throws IOException {
super(8080);
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
System.out.println("Running!");
}
public static void main(String[] args) {
try {
new App();
} catch (IOException ioe) {
System.err.println("Couldn't start server:\n" + ioe);
}
}
@Override
public Response serve(IHTTPSession session) {
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {}
String msg = "<html><body>Hello server</body></html>";
return newFixedLengthResponse(msg);
}
}
Aucun commentaire:
Enregistrer un commentaire