rpcgen

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 
#include 
#include "cal.h"

int * square_1_svc(int *x, struct svc_req *req) {
  static int result;
  result = (*x) * (*x);
  ret


gcc cal_proc.c cal_svc.c -o server

client:

#include 
#include 
#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

你可能感兴趣的:(rpc)