RPC Execution Binding Server Local Proc Local call
RPC Execution Binding Server Local Proc. Local call Stub Receive Query binding server Return Server Address Params packing Register Services Stub Remote Proc. Unpack Execute procedure Local call Wait Return Pack results Unpack result Caller Return Callee B. Prabhakaran 1
Sun RPC Specification Server Side: square. x: /* file name */ struct square_in { /* input argument */ long arg 1; } struct square_out { /* output argument */ long res 2; } program SQUARE_PROG { version SQUARE_VERS { square_out SQUAREPROC(square_in) = 1; /* procedure no. = 1 */ } = 1; /* version number */ } = 0 x 3123 0000; /* program number */ Compilation Procedure: rpcgen –C square. x /* -C: generate C prototypes in square. h */ B. Prabhakaran 2
Sun RPC: Server Side server. c: #include “unpipc. h” /* local headers */ #include “square. h” /* generated by RPCgen */ square_out * squareproc_1_svc (square_in *inp, struct svc_reg *rqstp) { static square_out out; out. res 1 = inp->arg 1 * inp->arg 1; return(&out); } Compilation Procedures: cc –c server. c –o server. o cc –c square_svc. c –o square_svc. o /* contains “main” */ cc –o server. o square_svc. o square. xdr. o libunpipc. a -lnsl Notes: libunpipc. a: library used in Stevens book; lnsl: Solaris system library Including RPC and XDR runtime functions B. Prabhakaran 3
Client Side client. c : #include “unpipc. h” /* local headers */ #include “square. h” /* generated by rpcgen */ main(int argc, char **argv) { CLIENT *cl; /* defined in rpc. h */ square_in in; square_out *outp; if (argc != 3) err_quit(“usage: client <hostname> <integer_value>”); cl = Clnt_create(argv[1], SQUARE_PROG, SQUARE_VERS, “tcp”); in. arg 1 = atol(argv[2]); if ((outp = squareproc_1(&in, cl) == NULL) err_quit(“%s”, clnt_sperror(cl, argv[1])); printf(“result: %dn”, outp->res 1); exit(0); } B. Prabhakaran 4
Client Compilation: cc –c client. c –o client. o cc –c square_clnt. c –o square_clnt. o cc –c square_xdr. c –o square_xdr. o cc –o client. o square_client. o square_xdr. o libunpipc. a -lnsl Notes: Rpcgen: generates square_xdr. c -> XDR data conversions square_clnt. c -> client stub Execution: client bsdi 11 -> result: 121 client 209. 76. 87. 90 22 -> result: 484 client nosuchhost 11 -> nosuchhost: RPC: Unknownhost…. Client localhost 11 -> localhost: RPC: Program not registered B. Prabhakaran 5
RPC Client-Server RPC Specification File square. x rpcgen #include square. h client. c square_clnt. c cc square_xdr. c Runtime library square_svc. c server. c cc server client B. Prabhakaran 6
RPC Implementation n Sending/receiving parameters: n n n Use reliable communication? : Use datagrams/unreliable? Implies the choice of semantics: how many times a RPC may be invoked. Reference Book: Unix Network Programming by Richard Stevens, Prentice-Hall. B. Prabhakaran 7
- Slides: 7