P. 1
Computer Communications

Computer Communications

|Views: 2,432|Likes:
Published by vanig05

More info:

Published by: vanig05 on Mar 10, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

07/03/2013

pdf

text

original

If we use RPCgen, then our work is essentially reduced to writing a specification file.
This file has the procedure names, argument types, return types etc. Here we show a
simple RPC specification file ( spec.x ) for printing a message on some other machine :

program MESSAGEPROG {
version MESSAGEVERS {

int PRINTMESSAGE ( string ) = 1;

} = 1;

} = 99;

We will have to do some changes on the server as well as client side. The server program
( msg_proc.c ) will look like this :

#include
#inculde
#include "msg.h"
int *printmessage_1( msg )
char **msg;
{

. . . . .
. . . . .

}

On the client side the program ( client.c ) will look like

#include
#inculde
#include "msg.h"
main( int argc, char *argv[])
{

client *c1;
int *result;
char *server = argv[1];
char *message = argv[2];
if (( c1 = clnt_create( server, MESSAGEPROG, MESSAGEVERS, "tcp" )) ==

NULL

{

// error

}
result = printmessage_1( &message, c1);
. . . . .

}

After creating the specification file we give the command $rpcgen spec.x ( where
spec.x is the name of the specification file ). The following files actions are taken and the
files spec.h, spec_svc.c, spec_clnt.c get created :

Once we have these files we write
$cc msg_proc.c spec_svc.c
$cc client.c spec_clnt.c

1. When we start the server program it creates a socket and binds any local port to it. It
then calls svc_register, to register the program number and version. This function contacts
the port mapper to register itself.
2. When the client program is started it calls clnt_create. This call specifies the name of
the remote system, the program number, version number, and the protocol. This functions
contacts the port mapper and finds the port for the server ( Sun RPC supports both TCP
and UDP).
3. The client now calls a remote procedure defined in the client stub. This stub sends the
datagram/packet to the server, using the port number obtained in step two. The client
waits for a response transmitting the requests a fixed number of times in case of a
timeout. This datagram/packet is received by the server stub associated with the server
program. The server stub executes the called procedure. When the function returns to the
server stub it takes the return value, converts it to the XDR format and transmits it back
to the client. The client stub receives the response, converts it as required and returns to
the client program

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->