Add some trace in error paths.
[TD_SR.git] / TD2 / client / Main.java
CommitLineData
18eb400b
JB
1import java.io.*;
2
3
4public class Main {
5
58312685 6 /**
b9a33c97 7 * main for testing ClientSimplifie
58312685 8 */
2c648f75 9 private static void main1() {
e018d1ec
JB
10 ClientSimplifie client = null;
11 BufferedReader userInput = null;
2c648f75
JB
12
13 try {
e018d1ec
JB
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 }
2c648f75 25 }
e018d1ec
JB
26 catch (IOException e) {
27 System.err.println("IOException: " + e);
b35728ff 28 e.printStackTrace();
2c648f75
JB
29 }
30 finally {
31 client.closeRWIO();
e018d1ec
JB
32 if (userInput != null) {
33 try {
34 userInput.close();
35 }
36 catch (IOException e) {
37 System.err.println("IOException: " + e);
b35728ff 38 e.printStackTrace();
e018d1ec
JB
39 }
40 }
2c648f75
JB
41 }
42 }
18eb400b 43
c4aaaeca
JB
44 /**
45 * main for text based message broadcasting
46 */
47 public static void main2() {
e018d1ec
JB
48 SocketClient client = null;
49 Thread thS = null;
50 Thread thR = null;
18eb400b 51
e018d1ec
JB
52 try {
53 client = new SocketClient();
54 thS = new Thread(new ThreadClientSend(client));
55 thR = new Thread(new ThreadClientReceive(client));
2c648f75
JB
56 thS.setName("thS");
57 thS.start();
58 thR.setName("thR");
59 thR.start();
e018d1ec
JB
60 }
61 catch (Exception e) {
62 System.err.println("Exception: " + e);
b35728ff 63 e.printStackTrace();
e018d1ec
JB
64 }
65 finally {
66 try {
67 thS.join();
68 thR.join();
69 }
70 catch (InterruptedException e) {
71 System.err.println("InterruptedException: " + e);
72 e.printStackTrace();
73 }
74 client.closeRWIO();
75 }
18eb400b
JB
76 }
77
c4aaaeca
JB
78 public static void main(String[] args) {
79 SocketClient client = null;
80 Thread thS = null;
81 Thread thR = null;
82
83 try {
1a8b0826 84 client = new SocketClient(true);
c4aaaeca
JB
85 thS = new Thread(new ThreadClientoSend(client));
86 thR = new Thread(new ThreadClientoReceive(client));
87 thS.setName("thoS");
88 thS.start();
89 thR.setName("thoR");
90 thR.start();
91 }
92 catch (Exception e) {
93 System.err.println("Exception: " + e);
b35728ff 94 e.printStackTrace();
c4aaaeca
JB
95 }
96 finally {
97 try {
98 thS.join();
99 thR.join();
100 }
101 catch (InterruptedException e) {
102 System.err.println("InterruptedException: " + e);
103 e.printStackTrace();
104 }
105 client.closeRWIO();
106 }
107 }
108
18eb400b 109}