boardgame
Class Server

java.lang.Object
  extended by boardgame.Server
All Implemented Interfaces:
java.lang.Runnable

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

Generic boardgame server. TODO The winner determination in case of a client error won't make sense unless it's a 2-player game. TODO The facility for the board to issue moves by returning Move.BOARD as the turn has not been tested all that well. TODO handling of Move.getReceivers() is not well tested. To start a server, execute its run() method. This will listen for clients and launch handler threads for each before returning. Any further work is done by these handler threads. The GUI dispatch thread may also call certain methods. Note that the call to run() returns as soon as the ClientHandler threads are started. A note on synchronization: The methods of this class will be called by 3 types of threads: - A) The thread executing the run() method - B) The ClientHandler threads (started by the run() method) - C) The GUI Thread The entry points for these threads are synchronized on the Server object's lock, except for the run() method. This is because the thread would not release the lock while waiting for connections. For this reason it is unsafe to manipulate the Server object while the run() method may be executing, with the exception of the killServer() method. This could probably be fixed by using yet another thread to accept the connections. Calls to the GUI, if present, are done using the EventQueue.invokeLater() facility, so that they are invoked by the AWT event dispatch thread.


Field Summary
protected static boolean DBGNET
           
protected static java.lang.String DEFAULT_BOARDCLASS
           
protected static int DEFAULT_PORT
           
protected static int DEFAULT_TIMEOUT
           
protected static boolean DUMPBOARD
           
protected static java.lang.String LOG_DIR
           
protected static java.lang.String LOG_PREFIX
           
protected static java.lang.String LOG_SUFFIX
           
protected static int MAX_SERVERS
           
protected static java.lang.String OUTCOME_FILE
           
protected static java.lang.String VERSION
           
 
Constructor Summary
Server(Board b, boolean createGUI)
          Create a server which will create its own socket to listen on
Server(Board b, boolean createGUI, boolean qt, int svPort, int to)
          Create a server which will create its own socket to listen on
Server(Board b, boolean createGUI, boolean qt, java.net.ServerSocket ss, int to)
          Create a server which accepts two connections from the given socket.
 
Method Summary
 java.lang.String getHostName()
          Returns "localhost" or the hostname if the run() method has completed
 int getPort()
           
static void main(java.lang.String[] args)
           
 void run()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

protected static final java.lang.String VERSION
See Also:
Constant Field Values

DEFAULT_PORT

protected static final int DEFAULT_PORT
See Also:
Constant Field Values

DEFAULT_TIMEOUT

protected static final int DEFAULT_TIMEOUT
See Also:
Constant Field Values

DEFAULT_BOARDCLASS

protected static final java.lang.String DEFAULT_BOARDCLASS
See Also:
Constant Field Values

DBGNET

protected static final boolean DBGNET
See Also:
Constant Field Values

DUMPBOARD

protected static final boolean DUMPBOARD
See Also:
Constant Field Values

MAX_SERVERS

protected static final int MAX_SERVERS
See Also:
Constant Field Values

LOG_DIR

protected static final java.lang.String LOG_DIR
See Also:
Constant Field Values

OUTCOME_FILE

protected static final java.lang.String OUTCOME_FILE
See Also:
Constant Field Values

LOG_PREFIX

protected static final java.lang.String LOG_PREFIX
See Also:
Constant Field Values

LOG_SUFFIX

protected static final java.lang.String LOG_SUFFIX
See Also:
Constant Field Values
Constructor Detail

Server

public Server(Board b,
              boolean createGUI,
              boolean qt,
              java.net.ServerSocket ss,
              int to)
Create a server which accepts two connections from the given socket.


Server

public Server(Board b,
              boolean createGUI)
Create a server which will create its own socket to listen on


Server

public Server(Board b,
              boolean createGUI,
              boolean qt,
              int svPort,
              int to)
Create a server which will create its own socket to listen on

Method Detail

main

public static void main(java.lang.String[] args)

getHostName

public java.lang.String getHostName()
Returns "localhost" or the hostname if the run() method has completed


getPort

public int getPort()

run

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