1 public void run() {
2 Scanner scanner = null;
3 PrintWriter printWriter = null;
4 try {
5 scanner = new Scanner(System.in);
6 printWriter = new PrintWriter(socket.getOutputStream(), true/*auto flush*/);
7
8 Boolean eof = false;
9 while (!eof && scanner.hasNext()) {
10 String message = scanner.nextLine();
11 printWriter.println("Client-1: " + message);
12 if (QUIT.equals(message.trim())) {
13 eof = true;
14 }
15 }
16 } catch (IOException e) {
17 System.out.println("[Send message failed]" + e.toString());
18 } finally {
19 // close resource
20 if (null != scanner) {
21 scanner.close();
22 }
23 if (null != printWriter) {
24 printWriter.close();
25 }
26 try {
27 socket.close();
28 } catch (IOException e) {
29 System.out.println("[Close client socket failed]" + e.toString());
30 }
31 }
32 }