TD1: Refactor the client side code.
[TD_SR.git] / TD2 / client / ThreadClientReceive.java
index 42f5d918dec13672e1acdbefcb1cc233e108a656..70f21b61e5a7f8868ba8db2f2059e62a419fcd78 100644 (file)
@@ -1,35 +1,27 @@
 import java.util.concurrent.ThreadLocalRandom;
+import java.io.*;
 
 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);
+        try {
+            boolean end = false;
+            while (!end) {
+                String rline = client.receiveMsg();
+                if (rline.equals(".")) {
+                                       end = true;
+                }
+                System.out.println(Thread.currentThread().getName() + " a recu " + rline);
             }
         }
+        catch (IOException e) {
+            System.err.println("IOException: " + e);
+            e.printStackTrace();
+        }
     }
 }