TD2: Ensure chat clients will not send empty message.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 16 Mar 2018 20:23:36 +0000 (21:23 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 16 Mar 2018 20:23:36 +0000 (21:23 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TD2/IHM/IHM.java
TD2/IHM/ThreadIHMSend.java
TD2/client/ThreadClientSend.java
TD2/client/ThreadClientoSend.java

index a10c23dc1ae764d0f0dc981a12773c3f0d77c900..22624fcc9a8749b12819655f7a33dbf260094993 100644 (file)
@@ -94,6 +94,8 @@ public class IHM implements ActionListener {
             e.printStackTrace();
         }
         String mess = (String)sendMessages.remove(0);
+        if (mess.length() == 0)
+            return "";
         System.out.println("IHM -> message a envoyer : " + mess);
         return randName + "> " + mess;
     }
index 2b1a64aba6b80590f8505ed4dff8e70f8f764474..f8077c968fdf03ed6dc4098fc04670180418d282 100644 (file)
@@ -17,8 +17,10 @@ public class ThreadIHMSend implements Runnable {
                 if (line.equals(".")) {
                     end = true;
                 }
-                client.sendMsg(line);
-                System.out.println(Thread.currentThread().getName() + " a envoye " + line);
+                if (line.length() != 0) {
+                    client.sendMsg(line);
+                    System.out.println(Thread.currentThread().getName() + " a envoye " + line);
+                }
             }
         }
         catch (Exception e) {
index 399cfd3139f819247e3a301fe9c88a52b0ed9724..639228fe45f6eef313a2abd9998b92ca721c9b9d 100644 (file)
@@ -17,8 +17,10 @@ public class ThreadClientSend implements Runnable {
                 if (line.equals(".")) {
                     end = true;
                 }
-                client.sendMsg(line);
-                System.out.println(Thread.currentThread().getName() + " a envoye " + line);
+                if (line.length() != 0) {
+                    client.sendMsg(line);
+                    System.out.println(Thread.currentThread().getName() + " a envoye " + line);
+                }
             }
         }
         catch (IOException e) {
index 52db7d5abdcad564bc3dc80635086d265da27794..1d7e232ffd794bde82be90199f8662d283cf02f7 100644 (file)
@@ -38,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) {