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