Browse Source

refactoring: identation run()

remotes/origin/client-handler
Valentin Spiroski 11 months ago
parent
commit
d723aed449
  1. 16
      src/main/java/ClientHandler.java

16
src/main/java/ClientHandler.java

@ -16,9 +16,10 @@ public class ClientHandler implements Runnable {
@Override @Override
public void run() { public void run() {
try { try {
fromClientReader = new BufferedReader(new InputStreamReader(connectionToClient.getInputStream()));
toClientWriter = new PrintWriter(new OutputStreamWriter(connectionToClient.getOutputStream()));
fromClientReader = new BufferedReader (new InputStreamReader(connectionToClient.getInputStream()));
toClientWriter = new PrintWriter (new OutputStreamWriter(connectionToClient.getOutputStream()));
chatServer.broadcastMessage(name + " connected."); chatServer.broadcastMessage(name + " connected.");
String message = fromClientReader.readLine(); String message = fromClientReader.readLine();
@ -26,17 +27,21 @@ public class ClientHandler implements Runnable {
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);
}
} finally {
finally {
//chatServer.removeClient(this); //chatServer.removeClient(this);
chatServer.broadcastMessage(name + " disconnected."); chatServer.broadcastMessage(name + " disconnected.");
if (fromClientReader != null) { if (fromClientReader != null) {
try { try {
fromClientReader.close(); fromClientReader.close();
} catch (IOException e){
}
catch (IOException e){
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -50,5 +55,4 @@ public class ClientHandler implements Runnable {
toClientWriter.println(message); toClientWriter.println(message);
toClientWriter.flush(); toClientWriter.flush();
} }
} }
Loading…
Cancel
Save