Package it.polimi.ingsw.eriantys.server
Class Server
java.lang.Object
java.lang.Thread
it.polimi.ingsw.eriantys.server.Server
- All Implemented Interfaces:
Runnable
This class represents the application server thread. It handles all the clients, instantiating
ClientConnection objects for each of them, and exposes various methods-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect(String username, ClientConnection connection) Handles a user connection by processing aHandshakecommunication item.voiddisconnect(ClientConnection connection) Handles a user disconnection, causing an update on the internal state of the class.voidProcesses the server-side end of the game.getConnection(String username) A getter for the client connection instance of a user.voidhandleMessage(ConnectionMessage message) Handles a user request by processing aConnectionMessagecommunication item.booleanisConnected(String username) A method to know if a user with a specified identifier exists or not.static voidThe method is called to launch the server-side application.voidreconnect(String username, int gameId, String passcode, ClientConnection connection) Handles a user reconnection by processing aReconnectcommunication item.voidrun()voidsendHelp(HelpRequest helpRequest) Handles the processing of aHelpRequestcommunication item.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Field Details
-
name
- See Also:
-
-
Constructor Details
-
Server
Constructs aServerobject, starting theServerSocket.- Parameters:
port- the port number on which theServerwill run- Throws:
IOException- if theServerSocketcould not be opened
-
-
Method Details
-
main
The method is called to launch the server-side application.- Parameters:
args- the command line arguments
-
run
public void run() -
connect
Handles a user connection by processing aHandshakecommunication item.- Parameters:
username- the username requested by the clientconnection- a reference to the client connection instance
-
reconnect
Handles a user reconnection by processing aReconnectcommunication item.- Parameters:
username- the username which has been chosen by the client prior to its disconnectiongameId- the identifier of the game inside which the client was playing prior to its disconnectionpasscode- the hexadecimal code which has been associated with the client by the disconnection handling infrastructureconnection- a reference to the client connection instance
-
disconnect
Handles a user disconnection, causing an update on the internal state of the class.- Parameters:
connection- a reference to the client connection instance
-
isConnected
A method to know if a user with a specified identifier exists or not.- Parameters:
username- the target user- Returns:
trueif and only if aClientConnectionexists for the target username
-
getConnection
A getter for the client connection instance of a user.- Parameters:
username- the target user- Returns:
- a reference to the client connection
- Throws:
NoConnectionException- if no connection can be retrieved for the target player
-
handleMessage
Handles a user request by processing aConnectionMessagecommunication item.- Parameters:
message- the target message to process- Throws:
NoConnectionException- if no connection can be retrieved for the target player
-
sendHelp
Handles the processing of aHelpRequestcommunication item.- Parameters:
helpRequest- the target request to process- Throws:
NoConnectionException- if no connection can be retrieved for the target player
-
gameOver
Processes the server-side end of the game.- Parameters:
game- the identifier of the game which has been endedplayers- the list of usernames who played the game
-