diff --git a/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java b/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java index f46425d..48ee896 100644 --- a/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java +++ b/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java @@ -23,6 +23,7 @@ import static ch.zhaw.pm2.multichat.protocol.ConnectionHandler.State.*; * To Contact the Model Elements needed it also holds references to message and the Connectionhandler. */ public class ChatWindowController { + public Button sendButton; //TODO necessary to have a attribute when not used or delete? private ClientConnectionHandler connectionHandler; private ClientMessageList messages; private final WindowCloseHandler windowCloseHandler = new WindowCloseHandler(); @@ -156,10 +157,6 @@ public class ChatWindowController { connectionHandler.initialize(serverAddress, serverPort, userName); new Thread(connectionHandler).start(); - //register Listener //TODO what todo with methods? - //startConnectionHandlerListener(); - - // register window close handler rootPane.getScene().getWindow().addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, windowCloseHandler); } else { addError("It is not allowed to have spaces in username!"); @@ -240,6 +237,7 @@ public class ChatWindowController { * Nested Class in charge of Closing the wind */ class WindowCloseHandler implements EventHandler { + /** * //TODO * @@ -285,7 +283,7 @@ public class ChatWindowController { } /** - * Starts a new Listener for messages by using the observable Boolean. + * Starts a new Listener for messages by using the observable Boolean. */ private void messageListener() { messages.getChangedProperty().addListener(new ChangeListener() { diff --git a/client/src/main/resources/ch/zhaw/pm2/multichat/client/ChatWindow.fxml b/client/src/main/resources/ch/zhaw/pm2/multichat/client/ChatWindow.fxml index 263979e..7715a0a 100644 --- a/client/src/main/resources/ch/zhaw/pm2/multichat/client/ChatWindow.fxml +++ b/client/src/main/resources/ch/zhaw/pm2/multichat/client/ChatWindow.fxml @@ -12,74 +12,82 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
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 6762b0c..604865f 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 @@ -120,12 +120,10 @@ public abstract class ConnectionHandler { protected void sendData(String sender, String receiver, String type, String payload) { if (connection.isAvailable()) { new StringBuilder(); - String data = new StringBuilder() - .append(sender + "\n") - .append(receiver + "\n") - .append(type + "\n") - .append(payload + "\n") - .toString(); + String data = sender + "\n" + + receiver + "\n" + + type + "\n" + + payload + "\n"; try { connection.send(data); } catch (SocketException e) { diff --git a/server/src/main/java/ch/zhaw/pm2/multichat/server/Server.java b/server/src/main/java/ch/zhaw/pm2/multichat/server/Server.java index 982c6bf..be26302 100644 --- a/server/src/main/java/ch/zhaw/pm2/multichat/server/Server.java +++ b/server/src/main/java/ch/zhaw/pm2/multichat/server/Server.java @@ -6,8 +6,7 @@ import java.io.IOException; import java.net.SocketException; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.locks.Condition; -import java.util.concurrent.locks.ReentrantLock; + /** * This Class represents a Server. The user can start the programm with the port number as a argument. @@ -84,13 +83,11 @@ public class Server { * The connection will be registered in the connection registry if successful. */ private void start() { - ReentrantLock mutex = new ReentrantLock(); - Condition nameComplete = mutex.newCondition(); System.out.println("Server started."); try { while (true) { NetworkHandler.NetworkConnection connection = networkServer.waitForConnection(); - ServerConnectionHandler connectionHandler = new ServerConnectionHandler(connection, connections, mutex, nameComplete); + ServerConnectionHandler connectionHandler = new ServerConnectionHandler(connection, connections); new Thread(connectionHandler).start(); } } catch (SocketException e) { diff --git a/server/src/main/java/ch/zhaw/pm2/multichat/server/ServerConnectionHandler.java b/server/src/main/java/ch/zhaw/pm2/multichat/server/ServerConnectionHandler.java index 45820bb..25e7a49 100644 --- a/server/src/main/java/ch/zhaw/pm2/multichat/server/ServerConnectionHandler.java +++ b/server/src/main/java/ch/zhaw/pm2/multichat/server/ServerConnectionHandler.java @@ -14,13 +14,12 @@ import java.util.Map; import java.util.Objects; import java.util.Scanner; import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; /** * This class represents the connection between the server and a client and offers the serverside logic. - * The ServerConnectionHandler receives data send from the client aswell as sends data to the client. + * The ServerConnectionHandler receives data send from the client as well as sends data to the client. *

* The ServeConnectionHandler offers following functionality: *

@@ -48,10 +47,6 @@ public class ServerConnectionHandler extends ConnectionHandler implements Runnab private final int connectionId = connectionCounter.incrementAndGet(); private final Map connectionRegistry; - private final ReentrantLock mutex; - - private final Condition nameComplete; - private String userName = "Anonymous-" + connectionId; private State state = NEW; @@ -68,21 +63,19 @@ public class ServerConnectionHandler extends ConnectionHandler implements Runnab * * @param connection representing the socket connection between server and client * @param registry map containing all active connections between server and clients - * @param mutex to lock thread - * @param nameComplete condition to call threads + + */ public ServerConnectionHandler(NetworkHandler.NetworkConnection connection, - Map registry, ReentrantLock mutex, Condition nameComplete) { + Map registry) { super(); setConnection(connection); Objects.requireNonNull(connection, "Connection must not be null"); Objects.requireNonNull(registry, "Registry must not be null"); this.connectionRegistry = registry; - this.mutex = mutex; - this.nameComplete = nameComplete; } - /** + /** //TODO needed method? * @return the username of the connected client */ public String getUserName() {