Class SimpleMessageSender

java.lang.Object
com.example.server.sender.SimpleMessageSender
All Implemented Interfaces:
MessageSender

public class SimpleMessageSender extends Object implements MessageSender
Class responsible for handling message sending functionality within a server application.
  • Constructor Details

    • SimpleMessageSender

      public SimpleMessageSender(LastMessages lastMessages, MessageQueue<BodyMessage> messageQueue)
      Constructor for SimpleMessageSender.
      Parameters:
      lastMessages - The instance of LastMessages for managing the last messages.
      messageQueue - The message queue for storing and processing BodyMessages.
  • Method Details

    • sendMessageToClient

      public void sendMessageToClient(String nickname, String message, ChatInterface chatClient) throws IOException
      Sends a message from a user to all other clients except the sender.
      Specified by:
      sendMessageToClient in interface MessageSender
      Parameters:
      nickname - The nickname of the user sending the message.
      message - The message content to be sent.
      chatClient - The ChatInterface containing information about connected clients.
      Throws:
      IOException - if an I/O error occurs during message sending.
    • sendMessage

      public void sendMessage(ChatClient client, String message) throws IOException
      Sends a message to a specific chat client.
      Specified by:
      sendMessage in interface MessageSender
      Parameters:
      client - The ChatClient to whom the message is sent.
      message - The message content to be sent.
      Throws:
      IOException - if an I/O error occurs during message sending.
    • sendLastMessages

      public void sendLastMessages(ChatClient client) throws IOException
      Sends the last messages to a specific client upon connecting.
      Specified by:
      sendLastMessages in interface MessageSender
      Parameters:
      client - The ChatClient to whom the last messages are sent.
      Throws:
      IOException - if an I/O error occurs during message sending.