TD2: Make the IHM client with one receive thread and one send thread.
[TD_SR.git] / TD2 / IHM / ThreadIHMReceive.java
diff --git a/TD2/IHM/ThreadIHMReceive.java b/TD2/IHM/ThreadIHMReceive.java
new file mode 100644 (file)
index 0000000..3a57d5c
--- /dev/null
@@ -0,0 +1,30 @@
+import java.io.*;
+
+public class ThreadIHMReceive implements Runnable {
+    private SocketClient client;
+    private IHM clientIHM;
+
+    ThreadIHMReceive(SocketClient c, IHM ui) {
+        client = c;
+        clientIHM = ui;
+    }
+
+    public void run() {
+        try {
+            boolean end = false;
+            //FIXME: not exiting properly randomly from that loop!
+            while (!end) {
+                String rline = client.receiveMsg();
+                if (rline.equals(".")) {
+                    end = true;
+                }
+                clientIHM.writeMessage(rline);
+                System.out.println(Thread.currentThread().getName() + " a recu " + rline);
+            }
+        }
+        catch (IOException e) {
+            System.err.println("IOException: " + e);
+            e.printStackTrace();
+        }
+    }
+}