TCPServerThread.java 941 Bytes
Newer Older
Gabriele Civitarese's avatar
Gabriele Civitarese committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
import java.io.*; 
import java.net.*;

public class TCPServerThread extends Thread {
	private     Socket connectionSocket = null;
	private     BufferedReader inFromClient;
	private     DataOutputStream  outToClient;

	/* L'argomento del costruttore e' una established socket */
	public TCPServerThread(Socket s) {
		connectionSocket = s;

		try{
			inFromClient =	
				new BufferedReader(
					new InputStreamReader(connectionSocket.getInputStream())); 

			outToClient = 
				new DataOutputStream(connectionSocket.getOutputStream()); 
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void run() {
		String clientSentence; 
		String capitalizedSentence; 

		try {

			clientSentence = inFromClient.readLine(); 

			capitalizedSentence = clientSentence.toUpperCase() + '\n'; 

			outToClient.writeBytes(capitalizedSentence); 	    

			connectionSocket.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}