Client2

Client2 - fromServer = new BufferedReader( new...

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 Client2 { private static Socket connect( String host ) throws Exception { try { return new Socket( host, 3000 ); } catch ( ConnectException ce ) { return null; } } public static void main( String [] arg ) throws Exception { Socket socket; BufferedReader stdIn; BufferedReader fromServer; PrintWriter toServer; String s; String result; do { socket = connect( arg[0] ); } while ( socket == null ); stdIn = new BufferedReader( new InputStreamReader( System.in ) );
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fromServer = new BufferedReader( new InputStreamReader( socket.getInputStream() ) ); toServer = new PrintWriter( new OutputStreamWriter( socket.getOutputStream() ), true ); while ( (s = stdIn.readLine()) != null ) { toServer.println( s ); result = fromServer.readLine(); System.out.println( "reverse: " + result ); } socket.close(); } }...
View Full Document

This note was uploaded on 12/16/2010 for the course CS 352 taught by Professor Staff during the Spring '06 term at Rutgers.

Ask a homework question - tutors are online