From: Jérôme Benoit Date: Wed, 14 Mar 2018 19:20:03 +0000 (+0100) Subject: TD2: Invert the stream on socket order: out first. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c4d2497c0d03e16d57bc40f26124a5d0ef4a5b75;p=TD_SR.git TD2: Invert the stream on socket order: out first. Signed-off-by: Jérôme Benoit --- 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()); }