Package it.meucci

Class Client

java.lang.Object
it.meucci.Client

public class Client extends Object
Represents client. Has some methods to write/send message from/to the Socket's input and output streams.
  • Field Details

    • userMessagesList

      public UserMessagesList userMessagesList
      The UserMessagesList object used to handle messages and users
  • Constructor Details

    • Client

      public Client(Inet4Address address, int port) throws IOException
      The client costructor.
      Parameters:
      address - The IP address of the ServerSocket
      port - The port on which the ServerSocket listens to
      Throws:
      IOException - When socket or DataOutputStream can't be created successfully.
  • Method Details

    • initListener

      public void initListener()
      Initializes the ReplyListener and starts it. Must be called once and after the successful creation of the client.
    • send

      public void send(Message message)
      Sends a message to the socket's ouput stream
      Parameters:
      message - The message to be serialized and sent
    • changeUsername

      public void changeUsername()
      Used to change user's username from the pending one.
    • stop

      public void stop() throws IOException
      Stops the client's socket
      Throws:
      IOException - inherited from socket.close() -- thrown when it's impossible to stop the client.
    • getSocket

      public Socket getSocket()
    • getUsername

      public String getUsername()
      Gets the current username. If it's null, `""` is automatically returned.
      Returns:
    • setPendingUsername

      public void setPendingUsername(String username)