Introduction to programming with Sun/ONC RPC: step 2

Step 1 Step 2 Step 3 Step 4 Step 5 Step 6

Step 2. Generate sample client and server code

In addition to generating files to support remote procedure calls, rpcgen also has options to generate template code for both the client and server. This makes it easy to make sure that you create the RPC handle properly and call the procedures correctly. It even allows you to generate a makefile.

If we want rpcgen to generate everything, we can just run:

rpcgen -a -C add.x

This will create the client (add_client.c), the server (add_server.c), and the makefile (makefile.add or Makefile.add, depending on whether you are using SunOS or Linux; OS X will not create a makefile).

If you want to generate only the client template code, run:

rpcgen -Sc -C add.x >add_client.c

If you want to generate only the server function template code, run:

rpcgen -Ss -C add.x >add_server.c

If you want to generate only the makefile, run:

rpcgen -Sm -C add.x >makefile.add

Note that the previous command will not work on OS X. The -Sm option is not supported.

Now we can compile our code by running:

make -f makefile.add (or Makefile.add)

To cut down on typing, let us rename makefile.add to makefile. This will allow us to simply type make with no parameters to recompile since by default make looks for a file named makefile or Makefile.

mv makefile.add makefile

If you need to change the name of the compiler to gcc because the default, cc, is not present on your system, you'll need to add a line to the makefile (for example, before the CFLAGS= line):


If you're using OS X, you'll have to compile the files individually (see step 3) until you write a makefile.

Continue to step 3

Back to step 1


Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh

Duis ultrices dolor sed erat.

Praesent ultrices, turpis vel feugiat tristique, mauris ligula pellentesque urna, quis interdum est enim mollis sem.

Ellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent orci leo, suscipit vel, pretium eu, viverra at, eros. Morbi cursus.