Browse Source

refactoring: comments in catch, finally in run()

remotes/origin/feature/client/make-input-field-buttons-interactive
Valentin Spiroski 11 months ago
parent
commit
cb912e039b
  1. 12
      src/main/java/ClientHandler.java

12
src/main/java/ClientHandler.java

@ -32,17 +32,17 @@ public class ClientHandler implements Runnable {
// Broadcast the client's message to all connected clients // Broadcast the client's message to all connected clients
chatServer.broadcastMessage(name + ": " + message); chatServer.broadcastMessage(name + ": " + message);
message = fromClientReader.readLine(); message = fromClientReader.readLine();
}
}
} }
catch (IOException e) { catch (IOException e) {
throw new RuntimeException(e);
throw new RuntimeException(e); // Handle exceptions by throwing a runtime exception
} }
finally { finally {
//chatServer.removeClient(this); //chatServer.removeClient(this);
chatServer.broadcastMessage(name + " disconnected.");
chatServer.broadcastMessage(name + " disconnected."); // Broadcast a message when the client is disconnected
// Close resources in the finally block
if (fromClientReader != null) { if (fromClientReader != null) {
try { try {
fromClientReader.close(); fromClientReader.close();
@ -54,7 +54,7 @@ public class ClientHandler implements Runnable {
if (toClientWriter != null) { if (toClientWriter != null) {
toClientWriter.close(); toClientWriter.close();
} }
}
}
} }
public void sendMessage(String message) { public void sendMessage(String message) {

Loading…
Cancel
Save