You are on page 1of 3

Ex.

No:5 RPC CLIENT-SERVER - CALCULATOR


02-01-17

AIM:

Design RPC Client Server Communication for calculator application.

ALGORITHM:

1 Declare the structure with two variables. Also declare functions for calculator namely
Addition, Subtraction, Multiplication and Division in calc.x file.
2 Rpcgen command is executed which automatically creates rpc client server programs.
3 Modify the code in server to accept input as parameters from client and perform
addition,subtraction,multiplication and division.
4 Modify the code in client to accept choice and numbers from user to perform
calculator operations and pass numbers as parameters to server.
5 Run client server code to verify results which is returned from server.

PROGRAM:

SERVER:

#include "calc.h"
int *add_1_svc(intpair *argp, struct svc_req *rqstp)
{
static int result;
result= argp->a+argp->b;
return &result;
}
int *sub_2_svc(intpair *argp, struct svc_req *rqstp)
{
static int result;
result=argp->a-argp->b;
return &result;
}
int *mul_3_svc(intpair *argp, struct svc_req *rqstp)
{
static int result;
result=argp->a*argp->b;
return &result;
}
int *div_4_svc(intpair *argp, struct svc_req *rqstp)
{
static int result;
result=argp->a/argp->b;
return &result;
}
CLIENT:

#include "calc.h"
void calc_prog_1(char *host,int a,int b)
{
CLIENT *clnt;
int *result_1;
intpair add_1_arg;
add_1_arg.a=a;
add_1_arg.b=b;
clnt = clnt_create (host, CALC_PROG, ADD_VERS, "udp");
result_1 = add_1(&add_1_arg, clnt);
printf("\nAddition %d\n",*result_1);
clnt_destroy (clnt);
}
void calc_prog_2(char *host,int a,int b)
{
CLIENT *clnt;
int *result_1;
intpair sub_2_arg;
sub_2_arg.a=a;
sub_2_arg.b=b;
clnt = clnt_create (host, CALC_PROG,SUB_VERS, "udp");
result_1 = sub_2 (&sub_2_arg, clnt);
printf("\nSubtraction %d\n",*result_1);
clnt_destroy (clnt);
}
void calc_prog_3(char *host,int a,int b)
{
CLIENT *clnt;
int *result_1;
intpair mul_3_arg;
mul_3_arg.a=a;
mul_3_arg.b=b;
clnt = clnt_create (host, CALC_PROG, MUL_VERS, "udp");
result_1 = mul_3 (&mul_3_arg, clnt);
printf("\nMultiplication %d\n",*result_1);
clnt_destroy (clnt);
}
void calc_prog_4(char *host,int a,int b)
{
CLIENT *clnt;
int *result_1;
intpair div_4_arg;
div_4_arg.a=a;
div_4_arg.b=b;
clnt = clnt_create (host, CALC_PROG, DIV_VERS, "udp");
result_1 = div_4(&div_4_arg, clnt);
printf("\nDivision %d\n",*result_1);
clnt_destroy (clnt);}
Int main (int argc, char *argv[])
{
char *host;
int a,b,opr;
host = argv[1];
printf("\nenter n1,n2\n");
scanf("%d%d",&a,&b);
printf("\nENTER the operation +,-,*,/\n");
scanf("%d",&opr);
switch(opr)
{
case 1:
{ calc_prog_1 (host,a,b);break;}
case 2:
{ calc_prog_2 (host,a,b);break;}
case 3:
{ calc_prog_3 (host,a,b);break;}
case 4:
{ calc_prog_4 (host,a,b);break;}
}
exit (0);
}
OUTPUT: CALCULATOR:

RESULT:

Thus RPC Calculator Application was successfully completed and executed.