Package net.targetr.wtm3.net.http
Class HttpServer
java.lang.Object
net.targetr.wtm3.net.http.HttpServer
Accepts HTTP and HTTPS connections on one port, starting a virtual-thread
HttpHandler for each socket.- Author:
- Dr Michael Gardiner
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new web server suitable for listening to a port for connections from web clients. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if the web server has entered the stopping state.voidlisten(int port, int backlog, InetAddress addr) Starts listening on a specific port for connection from web clients.voidsetResponder(ResponseGenerator responder) Sets the responder that will process requests and generate responses.voidstop()Closes the listener and waits up to one second for its loop to stop.
-
Constructor Details
-
HttpServer
public HttpServer()Creates a new web server suitable for listening to a port for connections from web clients.
-
-
Method Details
-
setResponder
Sets the responder that will process requests and generate responses.- Parameters:
responder- For responding to requests.
-
listen
public void listen(int port, int backlog, InetAddress addr) throws IOException, InterruptedException Starts listening on a specific port for connection from web clients.This method blocks until stopping.
- Parameters:
port- The port to listen for HTTP and HTTPS connections.backlog- requested maximum number of pending connectionsaddr- A specific network interface address to listen on or null for all.- Throws:
IOException- if binding or closing the listening socket failsInterruptedException- declared for compatibility; not currently thrown
-
isStopping
public boolean isStopping()Returns true if the web server has entered the stopping state.- Returns:
- true if stopping.
-
stop
public void stop()Closes the listener and waits up to one second for its loop to stop. Existing client connections are not closed by this method.
-