TD2: Fix the remaining bugs in the IHM chat client.
[TD_SR.git] / TD2 / server / BroadcastThreadService.java
index 7a39e7a72f4ba3384973baf9a5d717a10460f998..9ea5cdd5f90af52d4ee7ba2b23286f2bc61512f4 100644 (file)
@@ -43,9 +43,9 @@ public class BroadcastThreadService implements Runnable {
         * @throws IOException  [description]
         */
        public void doService(Socket clientSocket, ArrayList<PrintWriter> sharedList) throws IOException {
+               PrintWriter OWriter = new PrintWriter(clientSocket.getOutputStream());
                BufferedReader in;
                in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
-               PrintWriter OWriter = new PrintWriter(clientSocket.getOutputStream());
                sharedList.add(OWriter);
                boolean end = false;
                while (!end) {
@@ -54,13 +54,14 @@ public class BroadcastThreadService implements Runnable {
                                end = true; // le thread de service doit terminer
                                break; // do not broadcast the dot that will close all clients threads
                        }
+                       System.out.println("Broadcasting the message \"" + theLine + "\" received from " + clientSocket.toString());
                        broadcastMsg(theLine);
                }
                sharedList.remove(OWriter);
-               if (in != null)
-                       in.close();
                if (OWriter != null)
                        OWriter.close();
+               if (in != null)
+                       in.close();
                System.out.println("Fin du thread repondant au client, port "
                                                        + clientSocket.getPort());
        }