Browse Source

refactoring: identation run()

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

22
src/main/java/ClientHandler.java

@ -16,27 +16,32 @@ 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();
while (message!=null) { while (message!=null) {
chatServer.broadcastMessage(name + ": " + message); chatServer.broadcastMessage(name + ": " + message);
message = fromClientReader.readLine(); message = fromClientReader.readLine();
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
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