TD2: Ensure chat clients will not send empty message.
[TD_SR.git] / TD2 / client / ThreadClientSend.java
CommitLineData
e018d1ec 1import java.io.*;
2c648f75
JB
2
3public class ThreadClientSend implements Runnable {
4 private SocketClient client;
2c648f75
JB
5
6 ThreadClientSend(SocketClient c) {
7 client = c;
8 }
9
2c648f75 10 public void run() {
e018d1ec
JB
11 BufferedReader userInput = null;
12 try {
13 userInput = new BufferedReader(new InputStreamReader(System.in));
14 boolean end = false;
fcb90b76
JB
15 while (!end) {
16 String line = userInput.readLine();
6b300998 17 if (line.equals(".")) {
e018d1ec
JB
18 end = true;
19 }
73a5e231
JB
20 if (line.length() != 0) {
21 client.sendMsg(line);
22 System.out.println(Thread.currentThread().getName() + " a envoye " + line);
23 }
2c648f75 24 }
6b300998 25 }
e018d1ec
JB
26 catch (IOException e) {
27 System.err.println("IOException: " + e);
28 e.printStackTrace();
29 }
30 finally {
31 if (userInput != null) {
6b300998
JB
32 try {
33 userInput.close();
34 }
35 catch (IOException e) {
36 System.err.println("IOException: " + e);
8c3c3f61 37 e.printStackTrace();
6b300998
JB
38 }
39 }
2c648f75
JB
40 }
41 }
42}