X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TD2%2Fserver%2FBroadcastoThreadService.java;h=df56d31ed4c87c18a7041241be3d870f258fde23;hb=957ecacec542117816ecc362cfb9966040d4577b;hp=e8a3622a2d53a7396a8877b22b6830dc7769b661;hpb=da31e6daf7553c6b38ca83c428dd02a3aa8af853;p=TD_SR.git diff --git a/TD2/server/BroadcastoThreadService.java b/TD2/server/BroadcastoThreadService.java index e8a3622..df56d31 100644 --- a/TD2/server/BroadcastoThreadService.java +++ b/TD2/server/BroadcastoThreadService.java @@ -19,28 +19,37 @@ public class BroadcastoThreadService implements Runnable { try { doService(clientSocket, listoWriter); clientSocket.close(); - } catch (IOException e) { + } + catch (IOException e) { System.err.println("IOException : " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { - System.err.println("ClassNotFoundException: " + e); + System.err.println("ClassNotFoundException: " + e); e.printStackTrace(); } finally { try { if (this.clientSocket != null) this.clientSocket.close(); - } catch (IOException e) { + } + catch (IOException e) { System.err.println("IOException : " + e); e.printStackTrace(); } } } + /** + * Be careful, this function must be thread-safe + * @param clientSocket [description] + * @param sharedList [description] + * @throws IOException [description] + * @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) { @@ -52,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()); }