com.oreilly.servlet
Class DaemonHttpServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.oreilly.servlet.DaemonHttpServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
RemoteDaemonHttpServlet

public abstract class DaemonHttpServlet
extends javax.servlet.http.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, Serialized Form

Field Summary
protected  int DEFAULT_PORT
          The default listening port (1313)
 
Constructor Summary
DaemonHttpServlet()
           
 
Method Summary
 void destroy()
          Halts the thread listening for socket connections.
protected  int getSocketPort()
          Returns the socket port on which the servlet will listen.
abstract  void handleClient(java.net.Socket client)
          Handles a new socket connection.
 void init(javax.servlet.ServletConfig config)
          Begins a thread listening for socket connections.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

protected int DEFAULT_PORT
The default listening port (1313)

Constructor Detail

DaemonHttpServlet

public DaemonHttpServlet()
Method Detail

init

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

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Parameters:
config - the servlet config
Throws:
javax.servlet.ServletException - if a servlet exception occurs

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

handleClient

public abstract void handleClient(java.net.Socket client)
Handles a new socket connection. Subclasses must define this method.

Parameters:
client - the client socket

destroy

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

Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet