TD2: Ensure chat clients will not send empty message.
[TD_SR.git] / TD2 / client / ThreadClientoSend.java
index dd8d03b65a1679e2745a5974164fb0248dfadc87..1d7e232ffd794bde82be90199f8662d283cf02f7 100644 (file)
@@ -4,8 +4,7 @@ import java.util.Random;
 
 public class ThreadClientoSend implements Runnable {
     private SocketClient client;
-    //FIXME: use a random name by thread for now
-    //       should be setable
+    //FIXME: use a random name by thread for now, should be setable
     private String randName;
 
     ThreadClientoSend(SocketClient c) {
@@ -39,9 +38,11 @@ public class ThreadClientoSend implements Runnable {
                 if (line.equals(".")) {
                     end = true;
                 }
-                Message oMsg = new Message(randName, line, Calendar.getInstance());
-                client.sendoMsg(oMsg);
-                System.out.println(Thread.currentThread().getName() + " a envoye " + oMsg);
+                if (line.length() != 0) {
+                    Message oMsg = new Message(randName, line, Calendar.getInstance());
+                    client.sendoMsg(oMsg);
+                    System.out.println(Thread.currentThread().getName() + " a envoye " + oMsg);
+                }
             }
            }
         catch (IOException e) {
@@ -55,6 +56,7 @@ public class ThreadClientoSend implements Runnable {
                 }
                 catch (IOException e) {
                     System.err.println("IOException: " + e);
+                    e.printStackTrace();
                 }
             }
         }