From b5e5dc248b96f006946cecc0734f84ecdad2e314 Mon Sep 17 00:00:00 2001 From: Valentin Spiroski Date: Mon, 5 Feb 2024 14:03:07 +0100 Subject: [PATCH] refactoring: comments run() try --- src/main/java/ClientHandler.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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(); }