DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with Remote Procedure Calls (RPC)

The intermediate level

At the intermediate level, the application directly chooses the transport it wishes to use, factoring the value of NETPATH and the contents of /etc/netconfig into the choice as it sees fit.

Intermediate level: client side

The following code implements the client side of the same time service shown above, but written to the intermediate level of the RPC package.

The program requires the user to enter the transport over which the call will be made:

   #include <stdio.h>
   #include <rpc/rpc.h>
   #include <netconfig.h>		/* For netconfig structure */
   #include "time_prot.h"
   

#define TOTAL (30)

/* * Caller of trivial date service * usage: calltime hostname netid */ main(argc,argv) int argc; char *argv[]; { struct netconfig *nconf;

/* Declarations from previous example */

if (argc != 3) { fprintf(stderr,"usage: %s host netid\n",argv[0]); } nettype = argv[2]; if ((nconf = getnetconfigent(nettype)) == NULL) { fprintf(stderr, "Bad netid type: %s\n", nettype); exit(1); } client = clnt_tp_create(argv[1], TIME_PROG, TIME_VERS, nconf); if (client == NULL) { clnt_pcreateerror("Could not create client"); exit(1); }

/* Same as previous example after this point */

}

The netconfig structure can be obtained by a call to getnetconfigent(nettype). (See getnetconfig(NS) for more details.)

At this level, the program must explicitly make all decisions about network-selection.

Intermediate level: server side

This is the corresponding server. The administrator who starts the service is required to name, on the command line, the transport over which the service is provided:

   #include <stdio.h>
   #include <rpc/rpc.h>
   #include <netconfig.h>		/* For netconfig structure */
   #include "time_prot.h"
   

static void time_prog();

/* Service to supply Greenwich mean time */ /* usage: server netid */

main(argc,argv) int argc; char *argv[]; { SVCXPRT *transp; struct netconfig *nconf;

if (argc == 1) { fprintf(stderr, "usage: server netid \n"); exit(1); }

if ((nconf = getnetconfigent(argv[1])) == NULL) { fprintf(stderr, "Could not find info on %s\n", argv[1]); exit(1); }

transp = svc_tp_create(time_prog, TIME_PROG, TIME_VERS, nconf);

if (transp == NULL) { fprintf(stderr,"%s: cannot create %s service.\n", argv[0], argv[1]); exit(1) }

svc_run(); }

static void time_prog(rqstp, transp) struct svc_req *rqstp; SVCXPRT *transp; {

/* Code identical to Top Level version */ }


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005