X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TD2%2FThreadClientSend.java;fp=TD2%2FThreadClientSend.java;h=2ad2bcb1a922e8063bd4554a93d33a656917c8c3;hb=2c648f756e35448bf69e8a09670219bfc4b2fd52;hp=0000000000000000000000000000000000000000;hpb=ce28a0211974450cf5df46e2065fb39350e029ec;p=TD_SR.git diff --git a/TD2/ThreadClientSend.java b/TD2/ThreadClientSend.java new file mode 100644 index 0000000..2ad2bcb --- /dev/null +++ b/TD2/ThreadClientSend.java @@ -0,0 +1,39 @@ +import java.util.concurrent.ThreadLocalRandom; + +public class ThreadClientSend implements Runnable { + private SocketClient client; + private String msg = new String(); + + ThreadClientSend(SocketClient c) { + client = c; + } + + /** + * [setMsg description] + * @param m [description] + */ + public void setMsg(String m) { + msg = m; + } + + public void run() { + while (true) { + try { + client.sendMsg(msg); + System.out.println (Thread.currentThread().getName() + " a envoye " + 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(); + //} + } + } +}