Class Server

java.lang.Object
  extended byServer
All Implemented Interfaces:
java.lang.Runnable

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

This class creates a server from the Scrabble lobby. A server can only be created from the server lobby. Only one server can be created on any one machine. The server creates new ServerThreads when a client connects. All communications from the client are then handled by the ServerThread, with the Server overseeing game syncrhonization.

Version:
2.0
Author:
3GP01 - Hardev Bhamra, Deepak Chandarana, James Tompkin
See Also:
Client, ServerThread

Constructor Summary
Server()
           
 
Method Summary
 void close()
          Closes all server sockets, and attempts to close all ServerThreads.
 void createServer()
          Creates a server.
 Scrabble getScrabble()
          Gets the instance of the Scrabble class.
 boolean isGameInProgress()
          Returns true/false depending on whether the game of scrabble is in progress.
 boolean isListening()
          Returns true/false depending on whether the server is listening for new client connections.
 void run()
           
 void setGameInProgress(boolean gameInProgress)
          Sets whether the scrabble game is in progress or not.
 void setListening(boolean listening)
          Sets whether the server is listening for new client connections
 void start(java.lang.String dict, int players, int hints)
          Called from the lobby when 'create server' is pressed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Server

public Server()
Method Detail

getScrabble

public Scrabble getScrabble()
Gets the instance of the Scrabble class.

Returns:
Scrabble

isGameInProgress

public boolean isGameInProgress()
Returns true/false depending on whether the game of scrabble is in progress.

Returns:
boolean

isListening

public boolean isListening()
Returns true/false depending on whether the server is listening for new client connections.

Returns:
boolean

setGameInProgress

public void setGameInProgress(boolean gameInProgress)
Sets whether the scrabble game is in progress or not.

Parameters:
gameInProgress - A boolean toggle.

setListening

public void setListening(boolean listening)
Sets whether the server is listening for new client connections

Parameters:
listening - A boolean toggle.

createServer

public void createServer()
Creates a server. Only one server can exist on any one machine at any one time. The server controls up to four ServerThreads. The server controls the start of the game based on the number of players desired. The server creates a random seed to send to all clients for random bag synchronisation.


run

public void run()
Specified by:
run in interface java.lang.Runnable

start

public void start(java.lang.String dict,
                  int players,
                  int hints)
Called from the lobby when 'create server' is pressed. Takes input from lobby and creates a server based on the requirements of the game.

Parameters:
dict - The dictionary to use in the remote game.
players - The number of players required in the remote game.
hints - The number of hints required in the remote game.

close

public void close()
Closes all server sockets, and attempts to close all ServerThreads.