All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.oreilly.servlet.DaemonHttpServlet

java.lang.Object
   |
   +----javax.servlet.GenericServlet
           |
           +----javax.servlet.http.HttpServlet
                   |
                   +----com.oreilly.servlet.DaemonHttpServlet

public abstract class DaemonHttpServlet
extends HttpServlet
A superclass for HTTP servlets that wish to accept raw socket connections. DaemonHttpServlet starts listening for client requests in its init() method and stops listening in its destroy() method. In between, for every connection it receives, it calls the abstract handleClient(Socket client) method. This method should be implemented by the servlet subclassing DaemonHttpServlet. The port on which the servlet is to listen is determined by the getSocketPort() method.

Version:
1.0, 98/09/18
Author:
Jason Hunter, Copyright © 1998
See Also:
RemoteDaemonHttpServlet

Variable Index

 o DEFAULT_PORT
The default listening port (1313)

Constructor Index

 o DaemonHttpServlet()

Method Index

 o destroy()
Halts the thread listening for socket connections.
 o getSocketPort()
Returns the socket port on which the servlet will listen.
 o handleClient(Socket)
Handles a new socket connection.
 o init(ServletConfig)
Begins a thread listening for socket connections.

Variables

 o DEFAULT_PORT
 protected int DEFAULT_PORT
The default listening port (1313)

Constructors

 o DaemonHttpServlet
 public DaemonHttpServlet()

Methods

 o init
 public void init(ServletConfig config) throws ServletException
Begins a thread listening for socket connections. Subclasses that override this method must be sure to first call super.init(config).

Parameters:
config - the servlet config
Throws: ServletException
if a servlet exception occurs
Overrides:
init in class GenericServlet
 o getSocketPort
 protected int getSocketPort()
Returns the socket port on which the servlet will listen. A servlet can change the port in three ways: by using the socketPort init parameter, by setting the DEFAULT_PORT variable before calling super.init(), or by overriding this method's implementation.

Returns:
the port number on which to listen
 o handleClient
 public abstract void handleClient(Socket client)
Handles a new socket connection. Subclasses must define this method.

Parameters:
client - the client socket
 o destroy
 public void destroy()
Halts the thread listening for socket connections. Subclasses that override this method must be sure to first call super.destroy().

Overrides:
destroy in class GenericServlet

All Packages  Class Hierarchy  This Package  Previous  Next  Index