cal.x
program CALCULATOR{
version CALVERS {
int SQUARE(int) = 1;
} = 1;
} = 99;
rpcgen cal.x
cal_clnt.c
cal_svc.c
cal.h
server:
cal_proc.c
#include <stdio.h>
#include <rpc/rpc.h>
#include "cal.h"
int * square_1_svc(int *x, struct svc_req *req) {
static int result;
result = (*x) * (*x);
ret
client:
#include <stdio.h>
#include <rpc/rpc.h>
#include "cal.h"
int main(int argc, char **argv) {
CLIENT * clnt = clnt_create("node2", CALCULATOR, CALVERS, "tcp");
int x;
while(scanf("%d", &x) == 1) {
int *y = square_1(&x, clnt);
printf("%d * %d = %d\n", x, x, *y);
}
return 0;
}
gcc cal_clnt.c client.c -o client
./server
./client