TD2: Invert the stream on socket order: out first.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 14 Mar 2018 19:20:03 +0000 (20:20 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 14 Mar 2018 19:20:03 +0000 (20:20 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TD2/server/BroadcastThreadService.java
TD2/server/BroadcastoThreadService.java

index 7a39e7a72f4ba3384973baf9a5d717a10460f998..fd05e176447fa230421792430274ec96fcecc80d 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) {
@@ -57,10 +57,10 @@ public class BroadcastThreadService implements Runnable {
                        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());
        }
index 5ade5f328d87c830acc03a741e6eac18c880b3ef..7aa05eb5229c91281bc53068cd0b3a1d3a33058f 100644 (file)
@@ -48,8 +48,8 @@ public class BroadcastoThreadService implements Runnable {
         * @throws ClassNotFoundException [description]
         */
        public void doService(Socket clientSocket, ArrayList<ObjectOutputStream> sharedList) throws IOException, ClassNotFoundException {
-               ObjectInputStream OReader = new ObjectInputStream(clientSocket.getInputStream());
                ObjectOutputStream OWriter = new ObjectOutputStream(clientSocket.getOutputStream());
+               ObjectInputStream OReader = new ObjectInputStream(clientSocket.getInputStream());
                sharedList.add(OWriter);
                boolean end = false;
                while (!end) {
@@ -61,10 +61,10 @@ public class BroadcastoThreadService implements Runnable {
                        broadcastoMsg(roMsg);
                }
                sharedList.remove(OWriter);
-               if (OReader != null)
-                       OReader.close();
                if (OWriter != null)
                        OWriter.close();
+               if (OReader != null)
+                       OReader.close();
                System.out.println("Fin du thread repondant au client, port "
                                                        + clientSocket.getPort());
        }