Class GameServer

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

public class GameServer
extends java.lang.Thread

This class is the Server side Application for a client/server framework for 2 player turn-based games. Objects of this class are also used to communicate to individual threads via multithreading.

Author:
William Meyer 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
GameServer(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
 void createGameThread()
           
static void main(java.lang.String[] args)
          This starts execution of the GameServer application by running the server and listening for connecting clients.
 void resetGame()
          This method resets the current game after somebody wins, or there is a draw.
 void run()
          This method listens for communications from the client handled by this thread and provides a response so that the game continues.
 void sendNetworkObject(GameNetworkObject ono)
          This method sends a network object to a client
static void sendToAll(GameNetworkObject gno)
          This method sends a network object to all clients currently connected to the server.
 
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

GameServer

public GameServer(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

resetGame

public void resetGame()
This method resets the current game after somebody wins, or there is a draw.


sendNetworkObject

public void sendNetworkObject(GameNetworkObject ono)
This method sends a network object to a client

Parameters:
ono - The object to be sent

sendToAll

public static void sendToAll(GameNetworkObject gno)
This method sends a network object to all clients currently connected to the server.

Parameters:
gno - The object to be sent

createGameThread

public void createGameThread()

run

public void run()
This method listens for communications from the client handled by this thread and provides a response so that the game continues. The server runs the game and has the gameboard, and has the only true state of the game, and is the onlt entity that can change the game. The clients only send moves to the server, which updates the game board appropriately.

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

main

public static void main(java.lang.String[] args)
This starts execution of the GameServer application by running the server and listening for connecting clients. When a client does attempt to connect, a thread is spawned to communicate with that client, and it will be prompted for a username and password, and will not be allowed to play any games until a vaild username and password are supplied. Once the client logs on, the client will be matched with another client to play with, and a game will begin.

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