|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jogre.server.JogreServer
This abstract class is extended to create a server which is then executed using its run() method. To create a new server, such as a chess server, a class named something like ChessServer must extend this class and implement two abstract methods:
public abstract ServerConnectionThread connect (Socket connection, JogreServer server);
public abstract JogreModel getJogreModel ();
For the chess example these implemented methods will look something like the following:
// Return the correct type of connection thread for this server.
public ServerConnectionThread connect (Socket connection, JogreServer server) {
return new ChessServerConnectionThread (connection, server);
}
// Return the correct type of JogreModel (if the server keeps state).
public JogreModel getJogreModel() {
return new ChessModel ();
}
When a client connects to a JogreServer
a new
ServerConnectionThread
is created in its own Thread which will
handle all communciation between the server and the client. The connect
method returns the correct ServerConnectionThread to the server.
If a server keeps state then the abstract getJogreModel()
method should
return the correct implementation of the JogreModel
. If a game should keep
state (this allows demanding games to run faster but means other users can't
join a table and watch a game) then this method should simply return null.
Field Summary | |
protected ConnectionList |
connections
List of server connenction objects. |
static int |
DEFAULT_MAX_NUM_CONNECTED_USERS
Default number of maximum connected users. |
static int |
DEFAULT_SERVER_PORT
Default server port. |
protected int |
maxNumOfConnectedUsers
Maximum number of users which can connect to this server at any one time. |
protected int |
maxNumTables
Maximum number of tables this server can host at any one time. |
protected ServerConnectionThread |
serverConn
Server thread which listens to requests from a client. |
protected int |
serverPort
Server port we are listening on. |
protected TableList |
tableList
List of tables current being played on this server. |
protected String |
title
Title of a specified server. |
protected UserList |
userList
List of users which are currently connected to the server. |
Constructor Summary | |
JogreServer()
Default constructor which sets the title of the server from the "game.properties" file. |
|
JogreServer(String[] args)
This constructor does the same as the default server but also reads in additional arguments from the command prompt. |
Method Summary | |
abstract ServerConnectionThread |
connect(Socket connection,
JogreServer server)
Abstract method which dynamically loads the correct implementation of this ServerConnectionThread e.g. |
ConnectionList |
getConnections()
Return the ConnectionList object of connections to the server. |
abstract JogreModel |
getJogreModel()
Set the correct data for the Server. |
int |
getMaxNumOfConnectedUsers()
Return the maximum number of users which can be connected to this Server. |
int |
getServerPort()
Return the server port. |
TableList |
getTables()
Return the TableList object or table currently being played. |
UserList |
getUserList()
Returns the UserList object of current connected users. |
void |
run()
Run method which runs a new server and listens for clients on the specified port. |
void |
setServerPort(int serverPort)
Set the server port. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DEFAULT_SERVER_PORT
public static final int DEFAULT_MAX_NUM_CONNECTED_USERS
protected String title
protected ServerConnectionThread serverConn
protected int serverPort
protected int maxNumOfConnectedUsers
protected int maxNumTables
protected UserList userList
protected TableList tableList
protected ConnectionList connections
Constructor Detail |
public JogreServer()
public JogreServer(String[] args)
args
- Additional arguments from command line.Method Detail |
public abstract ServerConnectionThread connect(Socket connection, JogreServer server)
connection
- Socket connection to a user.server
- Link to the main JogreServer (and its fields such
as TableList, UserList and ConnectionList).public abstract JogreModel getJogreModel()
public void run()
public void setServerPort(int serverPort)
serverPort
- public int getServerPort()
public int getMaxNumOfConnectedUsers()
public UserList getUserList()
public TableList getTables()
public ConnectionList getConnections()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |