next up previous contents index
Next: More Examples Up: XDR Streams Previous: Files

Pipes and Sockets

If you are not familiar with pipes or sockets and XDR programming you should skip this section or consider the manual pages first.

There is no special support to create pipes or sockets in GRAPE. But if you have a pipe or socket, transmitting data over it is as simple as writing to or reading from a file. First you have to create an XDR stream by calling xdrrec_create and to set the XDR stream mode xdrp->x_op to XDR_ENCODE for writing or XDR_DECODE for reading, for reading you additionally have to call xdrrec_skiprecord. Now you can write or read the instance inst with

  if(!g_xdr_start(xdrp) ||
     !g_xdr_instance(xdrp, &inst) ||
     !g_xdr_end())
    fprintf(stderr, "transmission failed\n");
On writing you now have to call xdrrec_endofrecord to flush the data, finally the XDR stream can be destroyed with xdr_destroy.

The g_xdr_start functions writes/reads a magic number -- ``GXDR'' in bytes 9-12 of the stream -- and the global version and revision number (which can be obtained by g_xdr_get_version and g_xdr_get_revision and is for internal use only). g_xdr_end is needed to clean up some internal variables after the data has been transmitted.

For files g_xdr_open_file opens the file, creates the stream and writes the header, and g_xdr_close_file destroys the stream, cleans up and closes the file.



SFB 256 Universität Bonn and IAM Universität Freiburg

Copyright © by the Sonderforschungsbereich 256 at the Institut für Angewandte Mathematik, Universität Bonn.