TD2: Make the client send and receive object message.
[TD_SR.git] / TD2 / client / ThreadClientoSend.java
diff --git a/TD2/client/ThreadClientoSend.java b/TD2/client/ThreadClientoSend.java
new file mode 100644 (file)
index 0000000..2679180
--- /dev/null
@@ -0,0 +1,40 @@
+import java.io.*;
+
+public class ThreadClientoSend implements Runnable {
+    private SocketClient client;
+
+    ThreadClientoSend(SocketClient c) {
+        client = c;
+    }
+
+    public void run() {
+        BufferedReader userInput = null;
+        try {
+            userInput = new BufferedReader(new InputStreamReader(System.in));
+            boolean end = false;
+                       while (!end) {
+                               String line = userInput.readLine();
+                               if (line.equals(".")) {
+                    end = true;
+                }
+                Message oMsg = new Message("Name", line);
+                client.sendoMsg(oMsg);
+                System.out.println(Thread.currentThread().getName() + " a envoye " + oMsg);
+            }
+           }
+        catch (IOException e) {
+            System.err.println("IOException: " + e);
+            e.printStackTrace();
+        }
+        finally {
+            if (userInput != null) {
+                               try {
+                                       userInput.close();
+                               }
+                               catch (IOException e) {
+                                       System.err.println("IOException: " + e);
+                               }
+                       }
+        }
+    }
+}