0% found this document useful (0 votes)
867 views

RPC Client Server For Calculator Program

The document describes designing an RPC client-server program for a calculator application. It includes declaring structures and functions for addition, subtraction, multiplication and division in a calc.x file. The rpcgen command generates client and server code. The server accepts operands from the client and performs calculations. The client gets input from the user, calls the appropriate server function, and prints the result. Running the client and server verifies it works correctly.

Uploaded by

saranya n r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
867 views

RPC Client Server For Calculator Program

The document describes designing an RPC client-server program for a calculator application. It includes declaring structures and functions for addition, subtraction, multiplication and division in a calc.x file. The rpcgen command generates client and server code. The server accepts operands from the client and performs calculations. The client gets input from the user, calls the appropriate server function, and prints the result. Running the client and server verifies it works correctly.

Uploaded by

saranya n r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy