import java.net.*; import java.io.* ; class Client{ public static void main (String args[]) { Socket RemoteHostConnect ; BufferedReader RemoteInput ; String HostName = "localhost" ; int port = 5193 ; if ( args.length >= 1) { HostName = args[0] ; if ( args.length >= 2) { try { port = Integer.parseInt(args[1]) ; } catch (NumberFormatException nfe) { port = 0 ; // sure to fail } } } try { RemoteHostConnect = new Socket(HostName, port) ; RemoteInput = new BufferedReader( new InputStreamReader( RemoteHostConnect.getInputStream())) ; } catch ( IOException ioe ) { System.out.println("Cannot connect to " + HostName) ; return ; } try { System.out.println(RemoteInput.readLine()) ; } catch ( IOException ioe ) { System.out.println("Failure reading from socket") ; } } }