Class HttpServer

java.lang.Object
net.targetr.wtm3.net.http.HttpServer

public class HttpServer extends Object
Creates a new HTTPServer that listens to a specific port.

Creates and starts new HTTPHandlers when clients connect to a port.

Author:
Dr Michael Gardiner
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new web server suitable for listening to a port for connections from web clients.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if the web server has entered the stopping state.
    void
    listen(int port, int backlog, InetAddress addr)
    Starts listening on a specific port for connection from web clients.
    void
    Sets the responder that will process requests and generate responses.
    void
    Instructs the web server to stop listening for new connections.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HttpServer

      public HttpServer()
      Creates a new web server suitable for listening to a port for connections from web clients.
  • Method Details

    • setResponder

      public void setResponder(ResponseGenerator responder)
      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 - The number of connections that can be queed before being dropped.
      addr - A specific network interface address to listen on or null for all.
      Throws:
      IOException - If there is a problem accpeting connections.
      InterruptedException - If there is aproblem shutting down.
    • isStopping

      public boolean isStopping()
      Returns true if the web server has entered the stopping state.
      Returns:
      true if stopping.
    • stop

      public void stop()
      Instructs the web server to stop listening for new connections.