Module AM37

Class Client

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 constructor
    Client​(ViewInterface viewInterface, java.lang.String username, java.lang.String ipAddress)
    Default constructor
  • Method Summary

    Modifier and Type Method Description
    java.lang.String getIpAddress()
    ipAddress getter
    java.lang.String getUsername()
    username getter
    ViewInterface getView()
    viewInterface getter
    static void initClient​(ViewInterface viewInterface)
    Creates a new client instance
    void inputTimeout()
    Disconnects the client when the user does not respond for a certain amount of time
    static void main​(java.lang.String[] args)
    Launches the client
    void sendMessage​(Message message)
    Sends a message to the server
    void setCurrentPlayer​(boolean currentPlayer)
    Sets a flag allowing the user to send messages
    void setIpAddress​(java.lang.String ipAddress)
    ipAddress setter
    void setUsername​(java.lang.String username)
    Sets the username and, if possible, starts a connection
    void stopConnection()
    Terminates the connection with the server, closing the socket streams
    void writeSettingsToFile​(java.lang.String ip, java.lang.String username)
    Saves a new login configuration to a file

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Client

      public Client​(ViewInterface viewInterface)
      Default constructor

      Creates a new Client instance, assigning its viewInterface

      Parameters:
      viewInterface - the viewInterface to use
    • Client

      public Client​(ViewInterface viewInterface, java.lang.String username, java.lang.String ipAddress)
      Default constructor
      Parameters:
      username - the client's username
      ipAddress - the server address
  • Method Details

    • main

      public static void main​(java.lang.String[] args)
      Launches the client

      To determine which UI to use, this method uses command line arguments

      Parameters:
      args - command line arguments
    • initClient

      public static void initClient​(ViewInterface viewInterface)
      Creates a new client instance
      Parameters:
      viewInterface - the UI to use
    • getView

      public ViewInterface 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.IOException
      Saves a new login configuration to a file
      Parameters:
      ip - the server address
      username - the username
      Throws:
      java.io.IOException - if an I/O error occurs
    • sendMessage

      public void sendMessage​(Message message)
      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