java.lang.Object
it.polimi.ingsw.network.client.Client
public class Client
extends java.lang.Object
Representation of a client,
-
Constructor Summary
Constructors Constructor Description Client(ViewInterface viewInterface)Default constructorClient(ViewInterface viewInterface, java.lang.String username, java.lang.String ipAddress)Default constructor -
Method Summary
Modifier and Type Method Description java.lang.StringgetIpAddress()ipAddress getterjava.lang.StringgetUsername()username getterViewInterfacegetView()viewInterface getterstatic voidinitClient(ViewInterface viewInterface)Creates a new client instancevoidinputTimeout()Disconnects the client when the user does not respond for a certain amount of timestatic voidmain(java.lang.String[] args)Launches the clientvoidsendMessage(Message message)Sends a message to the servervoidsetCurrentPlayer(boolean currentPlayer)Sets a flag allowing the user to send messagesvoidsetIpAddress(java.lang.String ipAddress)ipAddress settervoidsetUsername(java.lang.String username)Sets the username and, if possible, starts a connectionvoidstopConnection()Terminates the connection with the server, closing the socket streamsvoidwriteSettingsToFile(java.lang.String ip, java.lang.String username)Saves a new login configuration to a file
-
Constructor Details
-
Method Details
-
main
public static void main(java.lang.String[] args)Launches the clientTo determine which UI to use, this method uses command line arguments
- Parameters:
args- command line arguments
-
initClient
Creates a new client instance- Parameters:
viewInterface- the UI to use
-
getView
viewInterface getter- Returns:
- the client's viewInterface
-
getUsername
public java.lang.String getUsername()username getter- Returns:
- the user's username
-
getIpAddress
public java.lang.String getIpAddress()ipAddress getter- Returns:
- the server address
-
setUsername
public void setUsername(java.lang.String username)Sets the username and, if possible, starts a connection- Parameters:
username- the chosen username- See Also:
startConnection()
-
setIpAddress
public void setIpAddress(java.lang.String ipAddress)ipAddress setter- Parameters:
ipAddress- the server address
-
setCurrentPlayer
public void setCurrentPlayer(boolean currentPlayer)Sets a flag allowing the user to send messages- Parameters:
currentPlayer- a boolean value
-
writeSettingsToFile
public void writeSettingsToFile(java.lang.String ip, java.lang.String username) throws java.io.IOExceptionSaves a new login configuration to a file- Parameters:
ip- the server addressusername- the username- Throws:
java.io.IOException- if an I/O error occurs
-
sendMessage
Sends a message to the server- Parameters:
message- the message to be sent
-
stopConnection
public void stopConnection()Terminates the connection with the server, closing the socket streams -
inputTimeout
public void inputTimeout()Disconnects the client when the user does not respond for a certain amount of time
-