From 73a5e231a2e60b6a4e141b89ff56208dcf225b0b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 16 Mar 2018 21:23:36 +0100 Subject: [PATCH] TD2: Ensure chat clients will not send empty message. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TD2/IHM/IHM.java | 2 ++ TD2/IHM/ThreadIHMSend.java | 6 ++++-- TD2/client/ThreadClientSend.java | 6 ++++-- TD2/client/ThreadClientoSend.java | 8 +++++--- 4 files changed, 15 insertions(+), 7 deletions(-) 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) { -- 2.34.1