TD2: Make the socket client multithreaded.
[TD_SR.git] / TD2 / ThreadClientSend.java
1 import java.util.concurrent.ThreadLocalRandom;
2
3 public class ThreadClientSend implements Runnable {
4 private SocketClient client;
5 private String msg = new String();
6
7 ThreadClientSend(SocketClient c) {
8 client = c;
9 }
10
11 /**
12 * [setMsg description]
13 * @param m [description]
14 */
15 public void setMsg(String m) {
16 msg = m;
17 }
18
19 public void run() {
20 while (true) {
21 try {
22 client.sendMsg(msg);
23 System.out.println (Thread.currentThread().getName() + " a envoye " + msg);
24 try {
25 Thread.sleep(ThreadLocalRandom.current().nextInt(101));
26 }
27 catch (InterruptedException e) {
28 System.err.println("InterruptedException: " + e);
29 }
30 }
31 catch (Exception e) {
32 System.err.println("Exception: " + e);
33 }
34 //finally {
35 // client.closeRWIO();
36 //}
37 }
38 }
39 }