// TalkClient // Burton Rosenberg // Tue Jul 15 12:40:50 EDT 1997 // An example of using sockets. See also TalkServer import java.io.* ; import java.net.* ; public class TalkClient { static final int PORT_NUMBER = 2234 ; public static void main( String [] args ) { if ( args.length < 1 ) { System.out.println("Usage: TalkClient hostname") ; System.exit(0) ; } String remoteHost = args[0] ; Socket client ; InputStream is ; OutputStream os ; PrintStream ps ; DataInputStream dis ; try { client = new Socket( remoteHost, PORT_NUMBER ) ; is = client.getInputStream() ; os = client.getOutputStream() ; ps = new PrintStream(os) ; dis = new DataInputStream( System.in ) ; String lineOfInput ; while ( (lineOfInput = dis.readLine()) != null ) { ps.println(lineOfInput) ; } client.close() ; } catch ( UnknownHostException uhe ) { System.out.println("Error: Can't find host " + remoteHost ) ; } catch ( IOException ioe ) { System.out.println("Error: "+ ioe.getMessage() ) ; } } }