com.objectwave.simpleSockets
Class ServeClient

java.lang.Object
  |
  +--com.objectwave.simpleSockets.ServeClient
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
ServeClassRequest, ServeHTTPClient

public class ServeClient
extends java.lang.Object
implements java.lang.Runnable

Shell class for implementing multithreaded servers.

Version:
2.0

Field Summary
protected  boolean alive
           
protected  boolean debug
           
protected  int id
           
protected  SimpleServer server
           
protected  ClientSocket socket
           
protected  java.lang.Thread thread
           
 
Constructor Summary
ServeClient(SimpleServer server, int ident)
           
ServeClient(SimpleServer server, int ident, java.lang.Thread t)
          Every instance of this class will run on its own thread.
 
Method Summary
 void bind(java.net.Socket s)
          Bind this awaiting client to the provided socket.
protected  int emitReply(java.lang.String reply)
           
protected  int emitReplyStream(java.io.InputStream in)
           
 java.lang.String getName()
           
protected  void handleSocketException(java.lang.Exception ex)
          Handle a socket exception during a readString().
 boolean isBound()
          Has a client been bound to us?
 void kill(boolean force)
           
protected  void loop()
           
 void loopForBinding()
          While we claim to be alive and we have no bound socket, wait.
 void pause()
          Sent the current thread into a wait state.
protected  java.lang.String processRequest(java.lang.String requestString)
          // Override this method to process your request.
 java.io.InputStream processRequestStream(java.lang.String requestString)
           
 void run()
          Loop waiting for a client to be bound to us.
protected  boolean runConnection()
           
protected  void terminateConnection()
           
 void unbind()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thread

protected java.lang.Thread thread

socket

protected ClientSocket socket

server

protected SimpleServer server

debug

protected boolean debug

alive

protected boolean alive

id

protected int id
Constructor Detail

ServeClient

public ServeClient(SimpleServer server,
                   int ident)

ServeClient

public ServeClient(SimpleServer server,
                   int ident,
                   java.lang.Thread t)
Every instance of this class will run on its own thread. It will be responsible for addressing communication with one client.

Method Detail

bind

public void bind(java.net.Socket s)
          throws java.io.IOException
Bind this awaiting client to the provided socket.

Parameters:
s - The socket this client should now handle.
java.io.IOException

emitReplyStream

protected int emitReplyStream(java.io.InputStream in)
                       throws java.io.IOException
java.io.IOException

emitReply

protected int emitReply(java.lang.String reply)
                 throws java.io.IOException
java.io.IOException

getName

public java.lang.String getName()

handleSocketException

protected void handleSocketException(java.lang.Exception ex)
Handle a socket exception during a readString().

Parameters:
ex - The socket exception to handle.

isBound

public boolean isBound()
Has a client been bound to us?


kill

public void kill(boolean force)

loop

protected void loop()
             throws java.io.IOException,
                    java.io.EOFException
java.io.IOException
java.io.EOFException

loopForBinding

public void loopForBinding()
While we claim to be alive and we have no bound socket, wait. Once a socket is bound, interrupt our wait state and return from method.


pause

public void pause()
           throws java.lang.InterruptedException
Sent the current thread into a wait state.

java.lang.InterruptedException

processRequestStream

public java.io.InputStream processRequestStream(java.lang.String requestString)

processRequest

protected java.lang.String processRequest(java.lang.String requestString)
// Override this method to process your request. Returning a string // from this method will imply to this to call emitReply();


run

public void run()
Loop waiting for a client to be bound to us.

Specified by:
run in interface java.lang.Runnable

runConnection

protected boolean runConnection()

terminateConnection

protected void terminateConnection()

unbind

public void unbind()