TD2: code cleanup in the client part.
[TD_SR.git] / TD2 / client / ThreadClientReceive.java
diff --git a/TD2/client/ThreadClientReceive.java b/TD2/client/ThreadClientReceive.java
new file mode 100644 (file)
index 0000000..42f5d91
--- /dev/null
@@ -0,0 +1,35 @@
+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);
+            }
+        }
+    }
+}