From 58312685472236da9be0138c9b5b450ca13387b1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 12 Mar 2018 15:40:19 +0100 Subject: [PATCH] TD2: code cleanup in the client part. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TD1/exo3/Main.java | 1 + TD2/{ => client}/ClientSimplifie.java | 0 TD2/{ => client}/Main.java | 29 ++++++++++++++--------- TD2/{ => client}/Makefile | 2 +- TD2/{ => client}/SocketClient.java | 1 + TD2/{ => client}/ThreadClientReceive.java | 3 --- TD2/{ => client}/ThreadClientSend.java | 7 ++---- TD2/{ => client}/concurrent_access.txt | 0 8 files changed, 23 insertions(+), 20 deletions(-) rename TD2/{ => client}/ClientSimplifie.java (100%) rename TD2/{ => client}/Main.java (56%) rename TD2/{ => client}/Makefile (99%) rename TD2/{ => client}/SocketClient.java (97%) rename TD2/{ => client}/ThreadClientReceive.java (91%) rename TD2/{ => client}/ThreadClientSend.java (86%) rename TD2/{ => client}/concurrent_access.txt (100%) diff --git a/TD1/exo3/Main.java b/TD1/exo3/Main.java index af0ba12..9b34b05 100644 --- a/TD1/exo3/Main.java +++ b/TD1/exo3/Main.java @@ -6,6 +6,7 @@ public class Main { public static void main (String[] args) { + //FIXME: Implement the args parsing to set this tree values dynamically final int BUFFER_SIZE = 1; final int PROD_NUMBER = 20; final int CONS_NUMBER = 20; diff --git a/TD2/ClientSimplifie.java b/TD2/client/ClientSimplifie.java similarity index 100% rename from TD2/ClientSimplifie.java rename to TD2/client/ClientSimplifie.java diff --git a/TD2/Main.java b/TD2/client/Main.java similarity index 56% rename from TD2/Main.java rename to TD2/client/Main.java index e7bd963..cc47bb7 100644 --- a/TD2/Main.java +++ b/TD2/client/Main.java @@ -3,11 +3,14 @@ import java.io.*; public class Main { + /** + * Main for testing ClientSimplifie + */ private static void main1() { SocketClient client = new SocketClient(); try { - client.sendMsg("Line 1 Line 2"); + client.sendMsg("Line1"); String msg = client.receiveMsg(); System.out.println(msg); } @@ -21,24 +24,28 @@ public class Main { public static void main (String[] args) { + SocketClient client = new SocketClient(); - try { - SocketClient client = new SocketClient(); + // try { ThreadClientSend thCS = new ThreadClientSend(client); - thCS.setMsg("Line1 Line2"); + //FIXME: Implement a loop based on user input to set dynamically the message to sent. + //for (int i = 0; i < 10; i++) { + // thCS.setMsg("Line" + i); + //} + thCS.setMsg("Line1"); Thread thS = new Thread(thCS); Thread thR = new Thread(new ThreadClientReceive(client)); thS.setName("thS"); thS.start(); thR.setName("thR"); thR.start(); - } - catch (Exception e) { - System.err.println("Exception: " + e); - } - finally { - client.closeRWIO(); - } + // } + // catch (Exception e) { + // System.err.println("Exception: " + e); + // } + // finally { + // client.closeRWIO(); + // } } diff --git a/TD2/Makefile b/TD2/client/Makefile similarity index 99% rename from TD2/Makefile rename to TD2/client/Makefile index 5c0e12f..5a7491f 100644 --- a/TD2/Makefile +++ b/TD2/client/Makefile @@ -47,7 +47,7 @@ JVM = java CLASSES = \ ClientSimplifie.java \ - Client.java \ + SocketClient.java \ ThreadClientSend.java \ ThreadClientReceive.java \ Main.java diff --git a/TD2/SocketClient.java b/TD2/client/SocketClient.java similarity index 97% rename from TD2/SocketClient.java rename to TD2/client/SocketClient.java index c4e74a3..48a93eb 100644 --- a/TD2/SocketClient.java +++ b/TD2/client/SocketClient.java @@ -54,6 +54,7 @@ public class SocketClient { * @param msg a string containing the message to send */ public synchronized void sendMsg(String msg) { + //NOTE: it's not really required with one socket writer thread. while (msg.isEmpty()) { try { wait(); diff --git a/TD2/ThreadClientReceive.java b/TD2/client/ThreadClientReceive.java similarity index 91% rename from TD2/ThreadClientReceive.java rename to TD2/client/ThreadClientReceive.java index 7cdb21a..42f5d91 100644 --- a/TD2/ThreadClientReceive.java +++ b/TD2/client/ThreadClientReceive.java @@ -30,9 +30,6 @@ public class ThreadClientReceive implements Runnable { catch (Exception e) { System.err.println("Exception: " + e); } - //finally { - // client.closeRWIO(); - //} } } } diff --git a/TD2/ThreadClientSend.java b/TD2/client/ThreadClientSend.java similarity index 86% rename from TD2/ThreadClientSend.java rename to TD2/client/ThreadClientSend.java index 2ad2bcb..69cd51a 100644 --- a/TD2/ThreadClientSend.java +++ b/TD2/client/ThreadClientSend.java @@ -9,8 +9,8 @@ public class ThreadClientSend implements Runnable { } /** - * [setMsg description] - * @param m [description] + * Message to sent setter + * @param m the text message to sent */ public void setMsg(String m) { msg = m; @@ -31,9 +31,6 @@ public class ThreadClientSend implements Runnable { catch (Exception e) { System.err.println("Exception: " + e); } - //finally { - // client.closeRWIO(); - //} } } } diff --git a/TD2/concurrent_access.txt b/TD2/client/concurrent_access.txt similarity index 100% rename from TD2/concurrent_access.txt rename to TD2/client/concurrent_access.txt -- 2.34.1