X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TD2%2FThreadClientReceive.java;fp=TD2%2FThreadClientReceive.java;h=7cdb21a46fd74527a5e50553f651ad58f292b1e7;hb=2c648f756e35448bf69e8a09670219bfc4b2fd52;hp=0000000000000000000000000000000000000000;hpb=ce28a0211974450cf5df46e2065fb39350e029ec;p=TD_SR.git diff --git a/TD2/ThreadClientReceive.java b/TD2/ThreadClientReceive.java new file mode 100644 index 0000000..7cdb21a --- /dev/null +++ b/TD2/ThreadClientReceive.java @@ -0,0 +1,38 @@ +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); + } + //finally { + // client.closeRWIO(); + //} + } + } +}