CITS3002 Computer Networks  
prev
next CITS3002 help3002 CITS3002 schedule  

The SunOS XDR Library, continued

Example:

The XDR routine to convert an integer is declared as

  bool    xdr_int(XDR *xdrs, int *ip)

If we wish to XDR encode an integer and send it to standard out we would firstly create an XDR stream to encode data:

  XDR *xdrs;
  int i;
          .
          .
  xdrstdio_create(xdrs, stdout, XDR_ENCODE);

and then call the function

  i = 23;
  if(!xdr_int(xdrs, &i)) {
          error-handling
  }

To decode reading from standard input we would create the stream using

  xdrstdio_create(xdrs, stdin, XDR_DECODE);

and use the same function call

  if(!xdr_int(xdrs, &i)) {
          error-handling
  }

to receive the integer into variable i.


CITS3002 Computer Networks, Lecture 10, Architecture independent applications, p21, 8th May 2024.