SessionThread

SessionThread - while ( (s = fromClient.readLine()) != null...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.*; import java.io.*; import java.net.*; public class SessionThread extends Thread { private Socket socket; public SessionThread( Socket s ) { socket = s; } public void run() { BufferedReader fromClient; PrintWriter toClient; String s; StringBuffer buffer; int i, limit; int j; char temp; try { fromClient = new BufferedReader( new InputStreamReader( socket.getInputStream() ) ); toClient = new PrintWriter( new OutputStreamWriter( socket.getOutputStream() ), true );
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: while ( (s = fromClient.readLine()) != null ) { buffer = new StringBuffer( s ); limit = buffer.length()/2; for ( i = 0 ; i < limit ; i++ ) { j = buffer.length() - 1 - i; temp = buffer.charAt( j ); buffer.setCharAt( j, buffer.charAt( i ) ); buffer.setCharAt( i, temp ); } toClient.println( buffer ); } socket.close(); } catch ( Exception e ) { System.out.println( "Exception in SessionThread." ); } } }...
View Full Document

Ask a homework question - tutors are online