Class OthelloServer

java.lang.Object
  extended by java.lang.Thread
      extended by GameServer
          extended by OthelloServer
All Implemented Interfaces:
java.lang.Runnable

public class OthelloServer
extends GameServer

This static side of this class is the Server side Application for a client/server Othello Game. Objects of this class are also used to communicate to individual threads via multithreading.

Author:
Adam Hauer Stony Brook University

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
OthelloServer(java.net.Socket initConnection, int initPlayerNumber)
          This constructor initializes the server by setting up all Object I/O to be used to communicate back and forth with this client.
 
Method Summary
static void main(java.lang.String[] args)
          This starts execution of the TicTacToeServer application by running the server and listening for connecting clients.
 void modifyScore()
          Compares the winner of the game with the playerNumber.
 void restartGame()
          This method restarts a game either after a draw or after a player has won.
 void run()
          This method listens for communications from the client handled by this thread and provides an adequate response such that the game progresses.
 
Methods inherited from class GameServer
assignColors, createProfile, findOpponent, getBoardReference, getOpponent, getPlayerNumber, login, resetStats, saveProfile, selectGame, sendNetworkObject, setBoardReference, setColor, setOpponent, setPlayerNumber
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OthelloServer

public OthelloServer(java.net.Socket initConnection,
                     int initPlayerNumber)
This constructor initializes the server by setting up all Object I/O to be used to communicate back and forth with this client.

Parameters:
initConnection - - socket that is connected to a client
initPlayerNumber - - represents the player number for the client that will be communicated with by this thread.
Method Detail

restartGame

public void restartGame()
This method restarts a game either after a draw or after a player has won.

Specified by:
restartGame in class GameServer

run

public void run()
This method listens for communications from the client handled by this thread and provides an adequate response such that the game progresses. Note that the server runs the game, the client is just a thin client, so the server always has the true game board and is the only entity that may change it.

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

modifyScore

public void modifyScore()
Compares the winner of the game with the playerNumber. Then modifies the stats of the player

Specified by:
modifyScore in class GameServer
Parameters:
winner - - the player that won the game

main

public static void main(java.lang.String[] args)
This starts execution of the TicTacToeServer application by running the server and listening for connecting clients. When a client does attempt to connect, if there is room in the game, a thread is spawned to communicate with that client

Parameters:
args - - command line arguments, not used in this application