Package kilim.http

Class HttpServer


  • public class HttpServer
    extends java.lang.Object
    A very rudimentary HTTP server bound to a specific given port.
    • Constructor Detail

      • HttpServer

        public HttpServer()
      • HttpServer

        public HttpServer​(int port,
                          java.lang.Class<? extends HttpSession> httpSessionClass)
                   throws java.io.IOException
        Creates a separate thread and a selector for the select loop and calls #listen(int, Class)listen
        Parameters:
        port - . Port to listen for http connections.
        httpSessionClass - An instance of the supplied class is created and bound to the incoming socket connection, and the task is scheduled for execution on the default scheduler.
        Throws:
        java.io.IOException
      • HttpServer

        public HttpServer​(int port,
                          HttpSession.StringRouter handler)
                   throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • listen

        public void listen​(int port,
                           java.lang.Class<? extends HttpSession> httpSessionClass,
                           Scheduler httpSessionScheduler)
                    throws java.io.IOException
        Sets up a listener on the supplied port, and when a fresh connection comes in, it creates a new instance of the httpSessionClass task and exceutes it on the supplied scheduler. It is the httpSession task's responsbility to close the socket.
        Parameters:
        port - . Port to listen for http connections.
        httpSessionClass - class of task to instantiation on incoming connection
        httpSessionScheduler - the scheduler on which to schedule the http session task.
        Throws:
        java.io.IOException