Escolar Documentos
Profissional Documentos
Cultura Documentos
1 - Introduo 2 - Gerao de um programa RPC 3 - Arquivo de Especificao RPC 4 - Arquivo de Cabealho RPC 5 - Cliente RPC 6 - Servidor RPC 7 - Etapas envolvidas em chamadas RPC
Pag. 1
1 Introduo
O RPC da Sun consiste das seguintes partes:
rpcgen, um compilador que toma a definio de uma interface de procedimento remoto e gera os stubs do cliente e do servidor. XDR (eXternal Data Representation), uma forma padro de codificao de dados de maneira portvel entre diferentes sistemas. Uma biblioteca run-time para tratar de todos os detalhes.
Pag. 2
date_proc.c
Arq. Especif. RPC
Stub do servidor
cc
date_svc.c
date.x
main( ) do cliente
Stub do cliente
rdate.c
cc
rdate
Pag. 4
O compilador rpcgen toma o arquivo date.x e gera dois novos arquivos .c, os stubs do cliente e do servidor, alm de um arquivo cabealho, que includo em ambos os stubs.
Pag. 5
/* date.x - Specification of remote date and time service. * * Define 2 procedures: * bin_date_1(): returns the binary time and date (no args) * str_date_1(): takes a binary time and returns a human* readable string. */ program DATE_PROG { version DATE_VERS { long BIN_DATE(void) = 1; /* procedure number = 1 */ string STR_DATE(long) = 2; /* procedure number = 2 */ } = 1; /* version number = 1 */ } = 0x31234567; /* program number = 0x31234567 */
Pag. 7
Pag. 8
Pag. 10
Pag. 11
#define DATE_PROG #define DATE_VERS #define BIN_DATE extern long #define STR_DATE extern char
Pag. 13
Pag. 14
5 - Cliente RPC
/* rdate.c - client program for remote date service. */ #include #include #include <stdio.h> <rpc/rpc.h> "date.h
main(int argc, char *argv[]) { CLIENT *cl; /* RPC handle */ char *server; long *lresult; /* return value from bin_date_1() */ char **sresult; /* return value from str_date_1() */
Pag. 15
if (argc != 2) { fprintf(stderr, "usage: %s hostname\n", argv[0]); exit(1); } server = argv[1]; /* Create the client "handle." */ if ( (cl = clnt_create(server, DATE_PROG, DATE_VERS, "udp")) == NULL) { /* Couldn't establish connection with server. */ clnt_pcreateerror(server); exit(2); }
Pag. 16
Pag. 17
6 - Servidor RPC
/* dateproc.c: remote procedures called by server stub. */ #include #include <rpc/rpc.h> "date.h" /* standard RPC include file */ /* file generated by rpcgen */
/* Return the binary date and time. */ long *bin_date_1() { static long timeval; /* must be static */ long time(); /* Unix function */ timeval = time((long *) 0); return(&timeval); }
Pag. 20
10
/* Convert a binary time and return a human readable string. */ char **str_date_1(long *bintime) { static char *ptr; /* must be static */ char *ctime(); /* Unix function */ ptr = ctime(bintime); return(&ptr); } /* convert to local time */
Pag. 21
11
(1)
Sistema Remoto
Pag. 23
12
Pag. 25
13
14