From c4d2497c0d03e16d57bc40f26124a5d0ef4a5b75 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 14 Mar 2018 20:20:03 +0100 Subject: [PATCH] TD2: Invert the stream on socket order: out first. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TD2/server/BroadcastThreadService.java | 6 +++--- TD2/server/BroadcastoThreadService.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/TD2/server/BroadcastThreadService.java b/TD2/server/BroadcastThreadService.java index 7a39e7a..fd05e17 100644 --- a/TD2/server/BroadcastThreadService.java +++ b/TD2/server/BroadcastThreadService.java @@ -43,9 +43,9 @@ public class BroadcastThreadService implements Runnable { * @throws IOException [description] */ public void doService(Socket clientSocket, ArrayList 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()); } diff --git a/TD2/server/BroadcastoThreadService.java b/TD2/server/BroadcastoThreadService.java index 5ade5f3..7aa05eb 100644 --- a/TD2/server/BroadcastoThreadService.java +++ b/TD2/server/BroadcastoThreadService.java @@ -48,8 +48,8 @@ public class BroadcastoThreadService implements Runnable { * @throws ClassNotFoundException [description] */ public void doService(Socket clientSocket, ArrayList 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()); } -- 2.34.1