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