Package com.example.server.sender
Class SimpleMessageSender
java.lang.Object
com.example.server.sender.SimpleMessageSender
- All Implemented Interfaces:
MessageSender
Class responsible for handling message sending functionality within a server application.
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleMessageSender
(LastMessages lastMessages, MessageQueue<BodyMessage> messageQueue) Constructor for SimpleMessageSender. -
Method Summary
Modifier and TypeMethodDescriptionvoid
sendLastMessages
(ChatClient client) Sends the last messages to a specific client upon connecting.void
sendMessage
(ChatClient client, String message) Sends a message to a specific chat client.void
sendMessageToClient
(String nickname, String message, ChatInterface chatClient) Sends a message from a user to all other clients except the sender.
-
Constructor Details
-
SimpleMessageSender
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 interfaceMessageSender
- 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
Sends a message to a specific chat client.- Specified by:
sendMessage
in interfaceMessageSender
- 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
Sends the last messages to a specific client upon connecting.- Specified by:
sendLastMessages
in interfaceMessageSender
- Parameters:
client
- The ChatClient to whom the last messages are sent.- Throws:
IOException
- if an I/O error occurs during message sending.
-