X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TD2%2Fclient%2FThreadClientReceive.java;fp=TD2%2Fclient%2FThreadClientReceive.java;h=42f5d918dec13672e1acdbefcb1cc233e108a656;hb=58312685472236da9be0138c9b5b450ca13387b1;hp=0000000000000000000000000000000000000000;hpb=2c648f756e35448bf69e8a09670219bfc4b2fd52;p=TD_SR.git diff --git a/TD2/client/ThreadClientReceive.java b/TD2/client/ThreadClientReceive.java new file mode 100644 index 0000000..42f5d91 --- /dev/null +++ b/TD2/client/ThreadClientReceive.java @@ -0,0 +1,35 @@ +import java.util.concurrent.ThreadLocalRandom; + +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); + } + } + } +}