TD2: Add response about serialization.
[TD_SR.git] / TD2 / client / Main.java
1 import java.io.*;
2
3
4 public class Main {
5
6 /**
7 * main for testing ClientSimplifie
8 */
9 private static void main1() {
10 ClientSimplifie client = null;
11 BufferedReader userInput = null;
12
13 try {
14 client = new ClientSimplifie();
15 userInput = new BufferedReader(new InputStreamReader(System.in));
16 boolean end = false;
17 while (!end) {
18 String line = userInput.readLine();
19 if (line.equals("."))
20 end = true;
21 client.sendMsg(line);
22 String rline = client.receiveMsg();
23 System.out.println(rline);
24 }
25 }
26 catch (IOException e) {
27 System.err.println("IOException: " + e);
28 }
29 finally {
30 client.closeRWIO();
31 if (userInput != null) {
32 try {
33 userInput.close();
34 }
35 catch (IOException e) {
36 System.err.println("IOException: " + e);
37 }
38 }
39 }
40 }
41
42 /**
43 * main for text based message broadcasting
44 */
45 public static void main2() {
46 SocketClient client = null;
47 Thread thS = null;
48 Thread thR = null;
49
50 try {
51 client = new SocketClient();
52 thS = new Thread(new ThreadClientSend(client));
53 thR = new Thread(new ThreadClientReceive(client));
54 thS.setName("thS");
55 thS.start();
56 thR.setName("thR");
57 thR.start();
58 }
59 catch (Exception e) {
60 System.err.println("Exception: " + e);
61 }
62 finally {
63 try {
64 thS.join();
65 thR.join();
66 }
67 catch (InterruptedException e) {
68 System.err.println("InterruptedException: " + e);
69 e.printStackTrace();
70 }
71 client.closeRWIO();
72 }
73 }
74
75 public static void main(String[] args) {
76 SocketClient client = null;
77 Thread thS = null;
78 Thread thR = null;
79
80 try {
81 client = new SocketClient(true);
82 thS = new Thread(new ThreadClientoSend(client));
83 thR = new Thread(new ThreadClientoReceive(client));
84 thS.setName("thoS");
85 thS.start();
86 thR.setName("thoR");
87 thR.start();
88 }
89 catch (Exception e) {
90 System.err.println("Exception: " + e);
91 }
92 finally {
93 try {
94 thS.join();
95 thR.join();
96 }
97 catch (InterruptedException e) {
98 System.err.println("InterruptedException: " + e);
99 e.printStackTrace();
100 }
101 client.closeRWIO();
102 }
103 }
104
105 }