From 61feb48a86993b794f7f816d4e51ff15e8be19bd Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sat, 16 Apr 2022 20:02:04 +0200 Subject: [PATCH] fixed Problem in processData in ConnectionHandler.java and Codecleanup --- .../pm2/multichat/client/ClientConnectionHandler.java | 3 +-- .../ch/zhaw/pm2/multichat/protocol/ConnectionHandler.java | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java b/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java index 769ff94..2ed34e5 100644 --- a/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java +++ b/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java @@ -27,8 +27,7 @@ public class ClientConnectionHandler extends ConnectionHandler implements Runnab private final SimpleStringProperty userName; private final SimpleObjectProperty state; - private final ClientMessageList - messages; + private final ClientMessageList messages; private final SimpleStringProperty serverAddress; private final SimpleIntegerProperty serverPort; diff --git a/protocol/src/main/java/ch/zhaw/pm2/multichat/protocol/ConnectionHandler.java b/protocol/src/main/java/ch/zhaw/pm2/multichat/protocol/ConnectionHandler.java index 604865f..6cc5450 100644 --- a/protocol/src/main/java/ch/zhaw/pm2/multichat/protocol/ConnectionHandler.java +++ b/protocol/src/main/java/ch/zhaw/pm2/multichat/protocol/ConnectionHandler.java @@ -97,7 +97,12 @@ public abstract class ConnectionHandler { } else if (scanner.hasNextLine()) { receiver.append(scanner.nextLine()); } else { - throw new ChatProtocolException("No Receiver found"); + throw new ChatProtocolException("No Sender found"); + } + if (scanner.hasNextLine()) { + receiver.append(scanner.nextLine()); + } else { + throw new ChatProtocolException("No Reciever found"); } if (scanner.hasNextLine()) { type.append(scanner.nextLine()); @@ -119,7 +124,6 @@ public abstract class ConnectionHandler { */ protected void sendData(String sender, String receiver, String type, String payload) { if (connection.isAvailable()) { - new StringBuilder(); String data = sender + "\n" + receiver + "\n" + type + "\n" +