X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TD2%2Fclient%2FThreadClientSend.java;fp=TD2%2Fclient%2FThreadClientSend.java;h=69cd51a445a3879caa270103dd8a7056dd08c9f6;hb=58312685472236da9be0138c9b5b450ca13387b1;hp=0000000000000000000000000000000000000000;hpb=2c648f756e35448bf69e8a09670219bfc4b2fd52;p=TD_SR.git diff --git a/TD2/client/ThreadClientSend.java b/TD2/client/ThreadClientSend.java new file mode 100644 index 0000000..69cd51a --- /dev/null +++ b/TD2/client/ThreadClientSend.java @@ -0,0 +1,36 @@ +import java.util.concurrent.ThreadLocalRandom; + +public class ThreadClientSend implements Runnable { + private SocketClient client; + private String msg = new String(); + + ThreadClientSend(SocketClient c) { + client = c; + } + + /** + * Message to sent setter + * @param m the text message to sent + */ + 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); + } + } + } +}