FileDocCategorySizeDatePackage
XDRInputExample.javaAPI DocExample1563Sat Jan 31 16:51:14 GMT 1998dcj.examples

XDRInputExample

public class XDRInputExample extends Object
Source code from "Java Distributed Computing", by Jim Farley. Class: XDRInputExample Example: 2-3 Description: A client program that uses an XDRInputStream. NOTE: This file contains incomplete example code only, which will not compile without additions and modifications.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)

    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.");
    }