Package it.fi.meucci

Class Server

java.lang.Object
it.fi.meucci.Server

public class Server extends Object
This class represents the server and contains some static methods used by other classes.
  • Constructor Details

  • Method Details

    • accept

      public void accept() throws IOException
      Accepts incoming connections, giving them a dedicated thread.
      Throws:
      IOException
    • getUsernames

      public ArrayList<String> getUsernames()
      Cycles through the threads and checks if they have a valid username.
      Returns:
      a list of valid usernames the user can chat with
    • send

      public void send(Message msg)
      Used by other RequestListeners to send messages to one another. It sends it also to the sender.
      Parameters:
      msg - The message to be sent
    • sendBroadcast

      public void sendBroadcast(Message msg) throws IOException
      Used by other RequestListeners to send messages to everyone. It sends it also to the sender.
      Parameters:
      msg - The message to be sent
      Throws:
      IOException
    • getListeners

      public ArrayList<RequestListener> getListeners()
      Returns:
      returns a list of listeners
    • isUserValid

      public boolean isUserValid(String username)
      Checks whether a username is valid or not.
      Parameters:
      username - the username to be checked
      Returns:
      true or false whether a username is valid or not.
    • isUserAvailable

      public boolean isUserAvailable(String username)
      Checks whether a username is available or not. Basically an ArrayList.contains() wrapper for better readability
      Parameters:
      username - the username to be checked
      Returns:
      true or false whether a username is available or not.