|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--Server
The Server class is a communications interface for an individual user who wants to host a multiplayer game of Sokoban.
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
Server(Game owner,
int port)
Server constructor |
Method Summary | |
void |
addUser(java.lang.String userName,
int robotNum)
Creates an add user command String for the robot passed and calls the sendToAll() method to send the command to all connected clients. |
int |
getMaxCon()
Returns the maximum number of connections allowed. |
int |
getPort()
Returns the number of the port to listen on. |
int[] |
getThreadNums()
Returns the thread numbers of each ServerThread in the clients vector. |
void |
run()
Initializes Server and waits for connections. |
void |
sendChangeLevelRequest(java.lang.String level,
int robotNum)
Creates a restart request command String for the robot passed and calls the sendToAll() method to send the command to all connected clients. |
void |
sendChat(java.lang.String user,
java.lang.String message)
Creates a chat command String for the robot passed and calls the sendToAll() method to send the command to all connected clients. |
void |
sendDisconnect(int robot)
Creates a disconnect command String for the robot passed and calls the sendToAll() method to send the command to all connected clients. |
void |
sendMap(java.lang.String level)
Sends the current Map to all clients. |
void |
sendMove(int robot,
Direction dir)
Creates a move command String for the robot passed and calls the sendToAll() method to send the command to all connected clients. |
void |
sendRestartMap()
Creates a restartMap command String for the robot passed and calls the sendToAll() method to send the command to all connected clients. |
void |
sendRestartRequest(int robotNum)
Creates a restart request command String for the robot passed and calls the sendToAll() method to send the command to all connected clients. |
protected void |
sendToAll(java.lang.String command)
Sends a command String to all connected clients. |
void |
sendUndo(int robot)
Creates an undo command String for the robot passed and calls the sendToAll() method to send the command to all connected clients. |
void |
setMaxCon(int max)
Sets the maximum number of connections allowed. |
void |
setPort(int port)
Sets the port to listen on. |
void |
stopListening()
Stops the Server from listening for connections. |
void |
stopServer()
Stops the server and sends a disconnect message to each client. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, 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 |
Constructor Detail |
public Server(Game owner, int port)
Server constructor
Pre-condition: none
Post-condition: Server class created; the internal owner variable is set to passed value.
owner
- provides a link back to the game.Method Detail |
public void run()
Initializes Server and waits for connections.
Pre-condition: none
Post-condition: server is waiting for connections
run
in class java.lang.Thread
public void sendMove(int robot, Direction dir)
Creates a move command String for the robot passed and calls the sendToAll() method to send the command to all connected clients.
Pre-condition: none
Post-condition: a move command String is created and sent to the sendToAll() method.
robot
- the robot number of the robot movingdir
- the direction the robot is movingpublic void sendUndo(int robot)
Creates an undo command String for the robot passed and calls the sendToAll() method to send the command to all connected clients.
Pre-condition: none
Post-condition: an undo command String is created and sent to the sendToAll() method.
robot
- the robot number of the robot movingpublic void sendDisconnect(int robot)
Creates a disconnect command String for the robot passed and calls the sendToAll() method to send the command to all connected clients.
Pre-condition: none
Post-condition: a disconnect command String is created and sent to the sendToAll() method.
robot
- the robot number of the robot movingpublic void sendChat(java.lang.String user, java.lang.String message)
Creates a chat command String for the robot passed and calls the sendToAll() method to send the command to all connected clients.
Pre-condition: none
Post-condition: a chat command String is created and sent to the sendToAll() method.
user
- the user name of the user who sent the messagemessage
- the message sent by the userpublic void sendRestartMap()
Creates a restartMap command String for the robot passed and calls the sendToAll() method to send the command to all connected clients.
Pre-condition: none
Post-condition: a restart command String is created and sent to the sendToAll() method.
public void sendRestartRequest(int robotNum)
Creates a restart request command String for the robot passed and calls the sendToAll() method to send the command to all connected clients.
Pre-condition: none
Post-condition: a restart command String is created and sent to the sendToAll() method.
public void sendChangeLevelRequest(java.lang.String level, int robotNum)
Creates a restart request command String for the robot passed and calls the sendToAll() method to send the command to all connected clients.
Pre-condition: none
Post-condition: a restart command String is created and sent to the sendToAll() method.
protected void sendToAll(java.lang.String command)
Sends a command String to all connected clients.
Pre-condition: the command parameter is a properly formatted String object.
Post-condition: the command parameter is sent to each ServerThread to be sent to each client.
command
- a formatted command String to be sent to each client connectedpublic void sendMap(java.lang.String level)
Sends the current Map to all clients.
Pre-condition: server has a map loaded in the board[][] in Map class
Post-condition: all clients' Map classes are updated.
public void addUser(java.lang.String userName, int robotNum)
Creates an add user command String for the robot passed and calls the sendToAll() method to send the command to all connected clients.
Pre-condition: none
Post-condition: an add user command String is created and sent to the sendToAll() method.
public void stopServer()
Stops the server and sends a disconnect message to each client.
Pre-condition: existing socket connection to a server
Post-condition: disconnect command sent to all clients; server stoped listening for connections
public void setPort(int port)
Sets the port to listen on.
port
- the port to listen onpublic int getPort()
Returns the number of the port to listen on.
public void setMaxCon(int max)
Sets the maximum number of connections allowed.
max
- the maximum number of connections allowedpublic int getMaxCon()
Returns the maximum number of connections allowed.
public int[] getThreadNums()
Returns the thread numbers of each ServerThread in the clients vector.
public void stopListening()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |