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