TD2: Make the IHM client with one receive thread and one send thread.
[TD_SR.git] / TD2 / IHM / ThreadIHMSend.java
diff --git a/TD2/IHM/ThreadIHMSend.java b/TD2/IHM/ThreadIHMSend.java
new file mode 100644 (file)
index 0000000..f173996
--- /dev/null
@@ -0,0 +1,30 @@
+import java.io.*;
+
+public class ThreadIHMSend implements Runnable {
+    private SocketClient client;
+    private IHM clientIHM;
+
+    ThreadIHMSend(SocketClient c, IHM ui) {
+        client = c;
+        clientIHM = ui;
+    }
+
+    public void run() {
+        BufferedReader userInput = null;
+        try {
+            boolean end = false;
+            while (!end) {
+                String line = clientIHM.getNextMessageToSend();
+                if (line.equals(".")) {
+                    end = true;
+                }
+                client.sendMsg(line);
+                System.out.println(Thread.currentThread().getName() + " a envoye " + line);
+            }
+        }
+        catch (Exception e) {
+            System.err.println("Exception: " + e);
+            e.printStackTrace();
+        }
+    }
+}