Documentation of 'edu.rit.http.HttpServer' Java class
HttpServer
edu.rit.http

Class HttpServer



  • public abstract class HttpServer
    extends java.lang.Object
    Class HttpServer provides a lightweight HTTP/1.0 server. The HTTP server is designed to be embedded inside another application.

    When constructed, the HTTP server starts a thread listening for connections to a given host and port. When a web browser sets up a connection, the HTTP server calls the process() method to process the request. This is an abstract method that must be overridden in a subclass. The process() method's arguments are an HttpRequest object from which the method reads the HTTP request message and an HttpResponse object to which the method writes the HTTP response message.

    The HTTP server assumes that the process() method will not perform any lengthy processing and will not block the calling thread. If the HTTP request requires lengthy processing or requires blocking, the process() method should spawn a separate thread to process the request. A thread pool may prove useful; see package java.util.concurrent.

    When a client opens a socket connection to the HTTP server, the server places a two-second timeout on reading the socket. If the client does not send an HTTP request message before the timeout, the HttpRequest's isValid() method returns false.

    • Constructor Summary

      Constructors 
      Constructor and Description
      HttpServer(java.net.InetSocketAddress address)
      Construct a new HTTP server.
      HttpServer(java.net.InetSocketAddress address, Logger logger)
      Construct a new HTTP server.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void close()
      Close this HTTP server.
      java.net.InetSocketAddress getAddress()
      Obtain the host and port to which this HTTP server is listening for connections.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HttpServer

        public HttpServer(java.net.InetSocketAddress address)
                   throws java.io.IOException
        Construct a new HTTP server. The HTTP server will print error messages on the standard error.
        Parameters:
        address - Host and port to which the HTTP server will listen for connections.
        Throws:
        java.io.IOException - Thrown if an I/O error occurred.
      • HttpServer

        public HttpServer(java.net.InetSocketAddress address,
                          Logger logger)
                   throws java.io.IOException
        Construct a new HTTP server. The HTTP server will print error messages using the given logger.
        Parameters:
        address - Host and port to which the HTTP server will listen for connections.
        logger - Error message logger. If null, the HTTP server will print error messages on the standard error.
        Throws:
        java.io.IOException - Thrown if an I/O error occurred.
    • Method Detail

      • getAddress

        public java.net.InetSocketAddress getAddress()
        Obtain the host and port to which this HTTP server is listening for connections.
        Returns:
        Host and port.
      • close

        public void close()
                   throws java.io.IOException
        Close this HTTP server.
        Throws:
        java.io.IOException - Thrown if an I/O error occurred.

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.