Laborator SPRC RPC - Remote Procedure Calls
Laborator SPRC RPC - Remote Procedure Calls
Client Server
routines routines
local procedure
call = (1) (10) (6) (5)
Client Server
stub stub
(8)
Network Network
routines routines
(3) = network communication
server stub
rpcgen remote_svc.c
RPC specification file
RPC
remote.x remote.h run-time
Library
remote_clnt.c
struct prime_result{
int array<MAXPRIMES>;
};
program PRIMEPROG{
version PRIMEVERS{
prime_result FIND_PRIMES(prime_request) = 1;
} = 1;
} = 0x32345678;
p_server.c
#include <rpc/rpc.h> int isprime(int n)
#include "primes.h" {
int i;
prime_result *find_primes_1(prime_request for (i = 2; i*i <= n; i++){
*request) if ((n % i) == 0) return
{ 0;
static prime_result result; }
static int prime_array[MAXPRIMES]; return 1;
int i, count = 0; }
/* Limitation of RPC:
Remote Procedure Call just supports single parameter
passing.
Hence, one have to define a specific data structure for
passing
more than one parameters */
program SHOP_PROG{
version SHOP_VERS{
items ADD12IT(items) = 1;
} = 1;
} = 0x32345678; /* please use your student ID */
Identifying an RPC Service
• There is a service registry called the port mapper, which keeps track of all RPC
services registered on a machine, and their transport endpoint addresses.
• In later implementations the port mapper is called “rpcbind”.
• Remote procedure is identified by THREE numbers:
{program number, version number, procedure number}
• While {program number, version number} identify a specific server program, the
procedure number identifies a procedure within that program
• The followings are the steps involved in locating an RPC service:
– When server starts, it create a endpoint to accept connection, so it binds an
arbitrary port number for this purpose;
– It then send a message to the portmapper registering the service;
– Portmapper add this mapping to its list;
– When client wants to find the service, it ask the portmapper by passing it
the program number, version number and protocol it uses;
– Portmapper returns the port number to the client;
– Client call the server procedure by sending an RPC call message to the port
it just got from the portmapper;
– The call message contains the serialized arguments and the procedure
number
Identifying an RPC Service
Identifying an RPC Service
Program numbers:
00000000-1FFFFFFF Admin by Sun Microsystems
20000000-3FFFFFFF User-defined
40000000-5FFFFFFF Transient
60000000-FFFFFFFF Reserved for future use