diff --git a/src/main/java/ClientHandler.java b/src/main/java/ClientHandler.java index 9f60c96..b6ae287 100644 --- a/src/main/java/ClientHandler.java +++ b/src/main/java/ClientHandler.java @@ -20,12 +20,16 @@ public class ClientHandler implements Runnable { public void run() { try { + // Set up input and output streams for communication with the client fromClientReader = new BufferedReader (new InputStreamReader(connectionToClient.getInputStream())); toClientWriter = new PrintWriter (new OutputStreamWriter(connectionToClient.getOutputStream())); - chatServer.broadcastMessage(name + " connected."); + chatServer.broadcastMessage(name + " connected."); // Broadcast a message when the client is connected + + // Read messages from the client and broadcast them to all clients String message = fromClientReader.readLine(); while (message!=null) { + // Broadcast the client's message to all connected clients chatServer.broadcastMessage(name + ": " + message); message = fromClientReader.readLine(); }