String host = argv[0];
// Default port is 5001
int port = 5001;
try {
port = Integer.parseInt(argv[1]);
}
catch (NumberFormatException e) {
System.out.println("Bad port number given, using default "
+ port);
}
// Try connecting to specified host and port
Socket serverConn = null;
try { serverConn = new Socket(host, port); }
catch (UnknownHostException uhe) {
System.out.println("Bad host name given.");
System.exit(1);
}
catch (Exception e) {
System.out.println("Error opening socket:");
e.printStackTrace();
}
try {
// Wrap an XDR stream around the input stream
XDRInputStream xin = new XDRInputStream(serverConn.getInputStream());
// Start reading expected data from XDR-formatted stream
int numVals = xin.readInt();
float val1 = xin.readFloat();
// . . .
}
catch (IOException ioe) {
System.out.println("Error getting stream from socket.");
}