import java.net.*; import java.io.* ; class LineCount{ public static void main (String args[]) { String RemoteHostName; InetAddress RemoteHostIP ; Socket RemoteHostConnect ; BufferedReader RemoteInput ; PrintWriter RemoteOutput ; int port = 3630 ; if (args.length > 0) { RemoteHostName = args[0] ; } else { RemoteHostName = "tryon.cs.unca.edu" ; } try { RemoteHostIP = InetAddress.getByName(RemoteHostName) ; } catch (UnknownHostException ue) { System.out.println("Cannot find host " + RemoteHostName); return; } System.out.println(RemoteHostIP.toString()) ; try { RemoteHostConnect = new Socket(RemoteHostIP, port) ; } catch ( IOException ioe ) { System.out.println("Cannot connect to " + RemoteHostName) ; return ; } try { RemoteInput = new BufferedReader( new InputStreamReader( RemoteHostConnect.getInputStream())) ; RemoteOutput = new PrintWriter(RemoteHostConnect.getOutputStream(), true) ; } catch ( IOException ioe ) { System.out.println("Cannot create I/O streams " + RemoteHostName) ; return ; } for (int i = 0; i < 10 ; ++i) { RemoteOutput.print("Tommy can you hear me #") ; RemoteOutput.println(i) ; String inString ; try { inString = RemoteInput.readLine() ; } catch ( IOException ioe ) { System.out.println("Failure reading from socket") ; return ; } System.out.println(inString) ; } } }