Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- } else if(messageType.equals("SENDMESSAGE") || messageType.equals("SENDMSG")) {
- String[] bodyParts = messageBody.split(" ");
- if(bodyParts.length > 1) {
- String recipient = bodyParts[0];
- String message = messageBody.substring(recipient.length()+1, messageBody.length());
- //find recipient
- Optional<ConnectedClient> recipientClient = connectedClients.stream().filter(c -> c.getUsername().equals(recipient)).findAny();
- if(recipientClient.isPresent()) {
- recipientClient.get().send(client.getUsername() + " -> " + recipientClient.get().getUsername() + ": " + message);
- client.send("Message sent");
- } else {
- client.send("Message could not be sent: no recipient by that name");
- }
- }
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement