Class ServerThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--ServerThread
All Implemented Interfaces:
java.lang.Runnable

public class ServerThread
extends java.lang.Thread

The ServerThread class is a communications interface between the server and the client.


Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ServerThread(Game owner, java.net.Socket socket, int threadNum)
          ServerThread constructor
 
Method Summary
 int getThreadNum()
          Returns the thread number of this connection.
 java.lang.String getUserName()
          Returns the user name of the client connected.
 void processCommand(java.lang.String command)
          Checks the command received from the client and determines what to do with the information
 void run()
          Initializes ServerThread, receives input from clients and closes the connection when finished.
 void sendCommand(java.lang.String command)
          Sends the command parameter to the client.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, 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
 

Constructor Detail

ServerThread

public ServerThread(Game owner,
                    java.net.Socket socket,
                    int threadNum)

ServerThread constructor

Pre-condition: none

Post-condition: ServerThread class created; owner, socket and threadNum are set to values passed

Parameters:
owner - provides a link back to the game
socket - the Socket connection to the client
threadNum - an identification number signifying which ServerThread it is
Method Detail

run

public void run()

Initializes ServerThread, receives input from clients and closes the connection when finished.

Pre-condition: existing socket connection to a client

Post-condition: data has been received and socket is closed

Overrides:
run in class java.lang.Thread

sendCommand

public void sendCommand(java.lang.String command)

Sends the command parameter to the client.

Pre-condition: existing socket connection to a client

Post-condition: command parameter is sent to the client

Parameters:
command - information to be sent to the client

processCommand

public void processCommand(java.lang.String command)

Checks the command received from the client and determines what to do with the information

Pre-condition: command contains the input sent from the client

Post-condition: the input has been processed and the Game is updated

Parameters:
command - the String recieved from the client to be processed

getThreadNum

public int getThreadNum()

Returns the thread number of this connection.

Returns:
threadNum - the thread number of this connection

getUserName

public java.lang.String getUserName()

Returns the user name of the client connected.

Returns:
userName - the user name of the client connected