|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Thread
com.antelmann.game.GameServer
public class GameServer
A GameServer hosts a GamePlay object that clients can play remotely by connecting to it and following this server's protocol. JPlayerClient is known to work with this server. Every GamePlay role is represented by a different NetConnection running in a different thread. The GameServer hosts a single game and then closes all connections once the game is over (i.e. when there are no more legal moves available); if you want to play another game, you need a new GameServer. The GameServer listens to new connections only if there are still game roles left that are not taken by a connection. The GameServer feature reconnects; i.e. if a client disconnects, the server is restarted to allow a new client to take that role - until all game roles are connected again.
GamePlay,
JPlayerClient| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
Thread.State, Thread.UncaughtExceptionHandler |
| Field Summary | |
|---|---|
static Handshake |
HANDSHAKE
this Handshake must be used when creating connections to this server |
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
GameServer(int serverPort,
GamePlay game,
int timeout,
Logger logger)
|
|
| Method Summary | |
|---|---|
void |
connectionLost(NetConnection con)
called when a connection caused an IOException during reading or writing; the connection may not have been closed at this point. |
SocketConnection |
createConnection(Socket socket)
produces a NetConnection based on the given socket. |
NetConnectionHandler |
createHandler(NetConnection con)
produces a NetConnectionHandler which will be started in a new Thread (created by the NetConnectionServer's ThreadFactory) to handle the given NetConnection and listens to messages. |
Handshake |
getHandshake()
returns a signature object used to identify the desired connection type handled by this ConnectionDispatcher object |
void |
handleMessage(Object message,
NetConnection con)
called when a message is received by the given NetConnection object |
static void |
main(String[] args)
starts a GameServer after some GUI selections |
void |
run()
|
void |
shutdown()
|
static void |
startServerWithGUI(Logger logger)
a conveninent way to start a GameServer with a little GUI; |
| 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 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Handshake HANDSHAKE
| Constructor Detail |
|---|
public GameServer(int serverPort,
GamePlay game,
int timeout,
Logger logger)
throws IOException
IOException| Method Detail |
|---|
public static void main(String[] args)
public static void startServerWithGUI(Logger logger)
throws IOException
IOException
public SocketConnection createConnection(Socket socket)
throws IOException
ConnectionDispatcher
createConnection in interface ConnectionDispatcherIOExceptionSocketConnection.createServerConnection(Socket, Handshake)public void connectionLost(NetConnection con)
NetConnectionHandler
connectionLost in interface NetConnectionHandlerpublic Handshake getHandshake()
ConnectionDispatcher
getHandshake in interface ConnectionDispatcher
public void handleMessage(Object message,
NetConnection con)
NetConnectionHandler
handleMessage in interface NetConnectionHandlerpublic void shutdown()
public void run()
run in interface Runnablerun in class Threadpublic NetConnectionHandler createHandler(NetConnection con)
ConnectionDispatcher
createHandler in interface ConnectionDispatcherMessageDelegator
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||