|
|
@ -16,6 +16,7 @@ public class ClientHandler implements Runnable { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
|
|
|
|
try { |
|
|
|
fromClientReader = new BufferedReader (new InputStreamReader(connectionToClient.getInputStream())); |
|
|
|
toClientWriter = new PrintWriter (new OutputStreamWriter(connectionToClient.getOutputStream())); |
|
|
@ -26,17 +27,21 @@ public class ClientHandler implements Runnable { |
|
|
|
chatServer.broadcastMessage(name + ": " + message); |
|
|
|
message = fromClientReader.readLine(); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
} |
|
|
|
|
|
|
|
catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
|
|
|
|
} finally { |
|
|
|
finally { |
|
|
|
//chatServer.removeClient(this); |
|
|
|
chatServer.broadcastMessage(name + " disconnected."); |
|
|
|
|
|
|
|
if (fromClientReader != null) { |
|
|
|
try { |
|
|
|
fromClientReader.close(); |
|
|
|
} catch (IOException e){ |
|
|
|
} |
|
|
|
catch (IOException e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
@ -50,5 +55,4 @@ public class ClientHandler implements Runnable { |
|
|
|
toClientWriter.println(message); |
|
|
|
toClientWriter.flush(); |
|
|
|
} |
|
|
|
|
|
|
|
} |