Add some trace in error paths.
[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 e.printStackTrace();
29 }
30 finally {
31 client.closeRWIO();
32 if (userInput != null) {
33 try {
34 userInput.close();
35 }
36 catch (IOException e) {
37 System.err.println("IOException: " + e);
38 e.printStackTrace();
39 }
40 }
41 }
42 }
43
44 /**
45 * main for text based message broadcasting
46 */
47 public static void main2() {
48 SocketClient client = null;
49 Thread thS = null;
50 Thread thR = null;
51
52 try {
53 client = new SocketClient();
54 thS = new Thread(new ThreadClientSend(client));
55 thR = new Thread(new ThreadClientReceive(client));
56 thS.setName("thS");
57 thS.start();
58 thR.setName("thR");
59 thR.start();
60 }
61 catch (Exception e) {
62 System.err.println("Exception: " + e);
63 e.printStackTrace();
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 }
76 }
77
78 public static void main(String[] args) {
79 SocketClient client = null;
80 Thread thS = null;
81 Thread thR = null;
82
83 try {
84 client = new SocketClient(true);
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);
94 e.printStackTrace();
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
109 }