TD2: Make the socket client multithreaded.
[TD_SR.git] / TD2 / Main.java
index 9e4fba5e97c7149ad19024311fd38e5eaa2b4e72..e7bd9638d3ce91f39700834fe09ee9679c407839 100644 (file)
@@ -1,19 +1,45 @@
-import java.io.*;\r
-\r
-\r
-public class Main {\r
-\r
-\r
-       public static void main (String[] args) {\r
-\r
-               ClientSimplifie client = new ClientSimplifie();\r
-\r
-               client.sendMsg("Line 1 Line 2");\r
-               String msg = client.receiveMsg();\r
-               System.out.println(msg);\r
-\r
-               client.closeRWIO();\r
-\r
-       }\r
-\r
-}\r
+import java.io.*;
+
+
+public class Main {
+
+       private static void main1() {
+               SocketClient client = new SocketClient();
+
+               try {
+                       client.sendMsg("Line 1 Line 2");
+                       String msg = client.receiveMsg();
+                       System.out.println(msg);
+               }
+               catch (Exception e) {
+                       System.err.println("Exception: " + e);
+               }
+               finally {
+                       client.closeRWIO();
+               }
+       }
+
+
+       public static void main (String[] args) {
+
+               try {
+                       SocketClient client = new SocketClient();
+                       ThreadClientSend thCS = new ThreadClientSend(client);
+                       thCS.setMsg("Line1 Line2");
+                       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();
+               }
+
+       }
+
+}