04: import java.util.*;
05: public class EchoThread extends Thread {
06: private Socket connectionSocket;
07: public EchoThread(Socket connectionSocket) {
08: this.connectionSocket = connectionSocket;
09: }
10: public void run() {
11: Scanner inFromClient = null;
12: DataOutputStream outToClient = null;
13: try {
14: inFromClient = new Scanner(connectionSocket.getInputStream());
15: outToClient =
16: new DataOutputStream(connectionSocket.getOutputStream());
17: String clientSentence = inFromClient.nextLine();
18: String capitalizedSentence = clientSentence.toUpperCase() + '\n';
19: outToClient.writeBytes(capitalizedSentence);
20:
21: }
22: catch (IOException e) {
23: System.err.println("Closing Socket connection");
24: }
25: finally {
26: try {
27: if (inFromClient != null)
28: inFromClient.close();
29: if (outToClient != null)
30: outToClient.close();
31: if (connectionSocket != null)
32: connectionSocket.close();
33: }
34: catch (IOException e) {
35: e.printStackTrace();
36: }
37: }
38: }
39: }