59ffbd0bab538c80a6b6f82f3ab094089fa7f7d1
[TD_SR.git] / TD2 / client / ThreadClientSend.java
1 import java.util.concurrent.ThreadLocalRandom;
2 import java.io.*;
3
4 public class ThreadClientSend implements Runnable {
5 private SocketClient client;
6
7 ThreadClientSend(SocketClient c) {
8 client = c;
9 }
10
11 public void run() {
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);
23 }
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 }
38 }
39 }
40 }