"Hello world" rpc call example - source

Hello World RPC

This is a VERY simple rpc example where the RPC server returns the strings "Hello world" when called. There are no input parameters

Two versions of the client are provided, one uses the client stub (firsttry_clnt.c) generated by RPCGEN, the second is functionally the same but makes a direct call to the rpc using the high-level function rpc_call().

Note there is no ...xdr.c file. The only data type passed is a string (the return value) and it can be translated by the primitive xdr routine xdr_wrapstring() (see man page). If the passed data can be translated by the primitive routines (e.g. xdr_int(), xdr_char(), etc) then there is no need for RPCGEN to build more complicated xdr routines. When the passed data is a composite of primitive data types, then RPCGEN creates a ...xdr.c file which uses combinations of calls to the primitives to do the translation.

Sample Procedures

Of the following, I wrote firsttry.x, firstmain.c firstmain2.c and firstsrvr.c -- the rest were automatically generated by RPCGEN.

  • Makefile - used to compile and link client and server.
  • firsttry.x - the rpcgen interface file
  • firsttry.h - generated by RPCGEN.
  • firstmain.c - the version of the client program that uses the RPCGEN generated client stub.
  • firsttry_clnt.c - the client stub generated by RPCGEN.
  • firstmain2.c - the version of the client program that uses rpccall() to call the rpc directly.
  • firstsrvr.c - the server procedure that returns "Hello world".
  • firsttry_svc.c - the server stub (server main program) generated by RPCGEN.