10
Invocação Remota de Invocação Remota de Procedimentos Procedimentos (RPC) (RPC) Alexandre Bragança Alexandre Bragança 2001 2001 DEI / ISEP DEI / ISEP

Invocação Remota de Procedimentos (RPC)

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Invocação Remota de Procedimentos (RPC)

Invocação Remota de Invocação Remota de Procedimentos Procedimentos

(RPC)(RPC)

Alexandre BragançaAlexandre Bragança

20012001

DEI / ISEPDEI / ISEP

Page 2: Invocação Remota de Procedimentos (RPC)

Modelo de ProgramaçãoModelo de Programação

Page 3: Invocação Remota de Procedimentos (RPC)

Cliente-ServidorCliente-Servidor

Page 4: Invocação Remota de Procedimentos (RPC)

FuncionamentoFuncionamento

Page 5: Invocação Remota de Procedimentos (RPC)

OSF DCEOSF DCE DCE = Distributed Computing EnvironmentDCE = Distributed Computing Environment OSF = Open Software FoundationOSF = Open Software Foundation

Page 6: Invocação Remota de Procedimentos (RPC)

Exemplo Exemplo Hello WorldHello World

/* file hellop.c *//* file hellop.c */#include <stdio.h> #include <stdio.h> void HelloProc(unsigned char * pszString) void HelloProc(unsigned char * pszString) { {

printf(“%s\n”, pszString); printf(“%s\n”, pszString); } }

/* file: hello.c, a stand-alone application */ /* file: hello.c, a stand-alone application */ #include “hellop.c” #include “hellop.c” void main(void) void main(void) { {

unsigned Char * pszString = “Hello, unsigned Char * pszString = “Hello, World”; World”; HelloProc(pszString); HelloProc(pszString); } }

Page 7: Invocação Remota de Procedimentos (RPC)

Definição do InterfaceDefinição do Interface

//file hello.idl//file hello.idl [ [ uuid(7a98c250-6808-11cf-b73b-00aa00b677a7), uuid(7a98c250-6808-11cf-b73b-00aa00b677a7), version(1.0) version(1.0) ] ] interface hello interface hello { { void HelloProc([in, string] unsigned char * void HelloProc([in, string] unsigned char * pszString); pszString); void Shutdown(void); void Shutdown(void); } }

• A função A função ShutdownShutdown permite que o cliente permite que o cliente ‘desligue’ o servidor‘desligue’ o servidor

Page 8: Invocação Remota de Procedimentos (RPC)

Geração dos Geração dos StubsStubs

Midl hello.idl

Hello.hA incluir no

cliente e no servidor

hello_c.c Stub Cliente

hello_s.cStub Servidor

Page 9: Invocação Remota de Procedimentos (RPC)

Implementação do código do Implementação do código do ServidorServidor

#include <stdlib.h>#include <stdio.h>#include "hello.h" // header file generated by MIDL compiler

void HelloProc(unsigned char * pszString){ printf("%s\n", pszString);}

void Shutdown(void){ RPC_STATUS status;

printf("Calling RpcMgmtStopServerListening\n"); status = RpcMgmtStopServerListening(NULL); printf("RpcMgmtStopServerListening returned: 0x%x\n", status); if (status) { exit(status); } printf("Calling RpcServerUnregisterIf\n"); status = RpcServerUnregisterIf(NULL, NULL, FALSE); printf("RpcServerUnregisterIf returned 0x%x\n", status); if (status) { exit(status); }}

Page 10: Invocação Remota de Procedimentos (RPC)

Compilação & ExecuçãoCompilação & Execução

• CompilaçãoCliente: helloc.exe helloc.c - Código do cliente hello_c.c – Stub

Servidor: hellos.exe hellos.c – Código do servidor hellop.c – Implementação dos serviços hello_s.c – Stub do servidor

• ExecuçãoNo servidor: hellosNo cliente: helloc