From: Jérôme Benoit Date: Fri, 16 Mar 2018 20:23:36 +0000 (+0100) Subject: TD2: Ensure chat clients will not send empty message. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=73a5e231a2e60b6a4e141b89ff56208dcf225b0b;p=TD_SR.git TD2: Ensure chat clients will not send empty message. Signed-off-by: Jérôme Benoit --- diff --git a/TD2/IHM/IHM.java b/TD2/IHM/IHM.java index a10c23d..22624fc 100644 --- a/TD2/IHM/IHM.java +++ b/TD2/IHM/IHM.java @@ -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; } diff --git a/TD2/IHM/ThreadIHMSend.java b/TD2/IHM/ThreadIHMSend.java index 2b1a64a..f8077c9 100644 --- a/TD2/IHM/ThreadIHMSend.java +++ b/TD2/IHM/ThreadIHMSend.java @@ -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) { diff --git a/TD2/client/ThreadClientSend.java b/TD2/client/ThreadClientSend.java index 399cfd3..639228f 100644 --- a/TD2/client/ThreadClientSend.java +++ b/TD2/client/ThreadClientSend.java @@ -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) { diff --git a/TD2/client/ThreadClientoSend.java b/TD2/client/ThreadClientoSend.java index 52db7d5..1d7e232 100644 --- a/TD2/client/ThreadClientoSend.java +++ b/TD2/client/ThreadClientoSend.java @@ -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) {