| 1 | import java.util.concurrent.ThreadLocalRandom; |
| 2 | |
| 3 | public class ThreadClientReceive implements Runnable { |
| 4 | private SocketClient client; |
| 5 | private String msg = new String(); |
| 6 | |
| 7 | ThreadClientReceive(SocketClient c) { |
| 8 | client = c; |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * @return the msg |
| 13 | */ |
| 14 | public String getMsg() { |
| 15 | return msg; |
| 16 | } |
| 17 | |
| 18 | public void run() { |
| 19 | while (true) { |
| 20 | try { |
| 21 | msg = client.receiveMsg(); |
| 22 | System.out.println (Thread.currentThread().getName() + " a recu " + msg); |
| 23 | try { |
| 24 | Thread.sleep(ThreadLocalRandom.current().nextInt(101)); |
| 25 | } |
| 26 | catch (InterruptedException e) { |
| 27 | System.err.println("InterruptedException: " + e); |
| 28 | } |
| 29 | } |
| 30 | catch (Exception e) { |
| 31 | System.err.println("Exception: " + e); |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | } |