iglu.net
Class ClientHandler

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--iglu.net.ClientHandler
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
WebHandler

public class ClientHandler
extends java.lang.Thread

The base class of the threads which the PortServer creates and starts to deal with client connections. It is sets up the communication socket with the client, and provides streams for talking with the client. It also closes them when it is done. However, it provide no further functionality.

Version:
1
Author:
Travis Bauer trbauer@indiana.edu

Field Summary
protected  java.net.Socket clientSocket
          does the talking through the socket
protected  java.io.InputStream in
          used for reading from the port
protected  PortServer myServer
          This clienthandler's server.
protected  java.io.OutputStream out
          used for writing to the port
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ClientHandler()
           
ClientHandler(java.net.Socket client, PortServer ms)
          Constructor for the ClientHandler.
 
Method Summary
 void doneWithNetworkAccess()
          Called before the class exits.
 void init(java.net.Socket client, PortServer ms)
           
protected  void internalDoneWithNetworkAccess()
          called before the public doneWithNetworkAccess.
 void processClient()
          Override this procedure to actually do the network access.
 void run()
          Calls processClient, doneWithNetworkAccess, then closes the streams and Socket.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

clientSocket

protected java.net.Socket clientSocket
does the talking through the socket


out

protected java.io.OutputStream out
used for writing to the port


in

protected java.io.InputStream in
used for reading from the port


myServer

protected PortServer myServer
This clienthandler's server. This is used to let the server handle the clients on the way out.

Constructor Detail

ClientHandler

public ClientHandler(java.net.Socket client,
                     PortServer ms)
              throws java.io.IOException
Constructor for the ClientHandler. Creates the socket and the streams for communication.


ClientHandler

public ClientHandler()
Method Detail

init

public void init(java.net.Socket client,
                 PortServer ms)
          throws java.io.IOException
java.io.IOException

run

public void run()
Calls processClient, doneWithNetworkAccess, then closes the streams and Socket. Then returns.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

processClient

public void processClient()
Override this procedure to actually do the network access. No functionality is provided here.


internalDoneWithNetworkAccess

protected void internalDoneWithNetworkAccess()
called before the public doneWithNetworkAccess. This class provides a way for intermediate descendents to do some processing after the connection is closed. We will leave "doneWithNetworkAcess" for clientHandlers which actually are used in an application and save this method for more abstract classes. Make sure you call super() if you override this method.


doneWithNetworkAccess

public void doneWithNetworkAccess()
Called before the class exits. Use this method to process what processClient accomplished.