X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TD2%2Fclient%2FThreadClientReceive.java;h=e3b727b7e3b0abc7cf619b1380ccc149a44218a5;hb=ef258436b31ba460b5038c5b7b62a06ea8968b2d;hp=42f5d918dec13672e1acdbefcb1cc233e108a656;hpb=58312685472236da9be0138c9b5b450ca13387b1;p=TD_SR.git diff --git a/TD2/client/ThreadClientReceive.java b/TD2/client/ThreadClientReceive.java index 42f5d91..e3b727b 100644 --- a/TD2/client/ThreadClientReceive.java +++ b/TD2/client/ThreadClientReceive.java @@ -1,35 +1,28 @@ import java.util.concurrent.ThreadLocalRandom; +import java.io.*; public class ThreadClientReceive implements Runnable { private SocketClient client; - private String msg = new String(); ThreadClientReceive(SocketClient c) { client = c; } - /** - * @return the msg - */ - public String getMsg() { - return msg; - } - public void run() { - while (true) { - try { - msg = client.receiveMsg(); - System.out.println (Thread.currentThread().getName() + " a recu " + msg); - try { - Thread.sleep(ThreadLocalRandom.current().nextInt(101)); - } - catch (InterruptedException e) { - System.err.println("InterruptedException: " + e); - } - } - catch (Exception e) { - System.err.println("Exception: " + e); + try { + boolean end = false; + //FIXME: Not exiting properly from that loop! + while (!end) { + String rline = client.receiveMsg(); + if (rline.equals(".")) { + end = true; + } + System.out.println(Thread.currentThread().getName() + " a recu " + rline); } } + catch (IOException e) { + System.err.println("IOException: " + e); + e.printStackTrace(); + } } }