0% found this document useful (0 votes)
4 views6 pages

DS(EX-1)

Uploaded by

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

DS(EX-1)

Uploaded by

nikhildeutsch03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

JEYANTH.

S
22IZ016

EXERCISE-1

AIM:
To implement Client server Implementation using Remote Procedure Protocol.

Remote Procedure Call:

★​ A remote procedure call is an interprocess communication technique that is used


for client-server based applications.
★​ It is also known as a subroutine call or a function call.

RPCGEN:

●​ RPCGEN is an interface generator pre-compiler for Sun Microsystems ONC


RPC (Open Network Computing RPC).
●​ It creates client and server stubs in C based on information contained within a file
●​ called IDL (interface definition file) file. This file is written in a language called
●​ RPCL – remote procedure call language.
●​ Client side program to get numbers from the user, to call the relevant method on
the server side and to send those numbers to that method on the server side.
●​ Server side program to do the addition and to send back the result to the client
side.

IDL:

●​ An IDL is a file (suffixed with .x) which optionally begins with a bunch of type
definitions and then defines the remote procedures.
●​ A set of remote procedures are grouped into a version.
●​ One or more versions are grouped into a program.
WORKING:

●​ Rpcbind:

●​ rpcinfo:
CODE:

1 ) Header File (add.h)

#define _ADD_H
#define _ADD_H
#include <rpc/rpc.h>
struct numbers {
int a;
int b;
};
typedef struct numbers numbers;
#define ADD_PROG 0x4562877
#define ADD_VERS 1
#define ADD 1
extern int *add_1(numbers *, CLIENT *);
extern int *add_1_svc(numbers *, struct svc_req *);

Compile this IDL file by using the following command :rpcgen -a -C add.x

2 ) Server Implementation (add_server.c)

#include <stdio.h>
#include <stdlib.h>
#include "add.h"
void add_prog_1(char *host, int num1, int num2) {
CLIENT *clnt;
int *result;
numbers add_1_arg;
clnt = clnt_create(host, ADD_PROG, ADD_VERS, "udp");
if (clnt == NULL) {
clnt_pcreateerror(host);
exit(1);
}
add_1_arg.a = num1;
add_1_arg.b = num2;
result = add_1(&add_1_arg, clnt);
if (result == (int *) NULL) {
clnt_perror(clnt, "call failed");
}
else
{
printf("Result: %d\n", *result);
}
clnt_destroy(clnt);
}
int main(int argc, char *argv[]) {
char *host;
if (argc < 4) {
printf("Usage: %s <server_host> <num1> <num2>\n", argv[0]);
exit(1);
}
host = argv[1];
int num1 = atoi(argv[2]);
int num2 = atoi(argv[3]);
add_prog_1(host, num1, num2);
return 0;
}

3 ) Client Implementation (add_client.c)

#include <stdio.h>
#include <stdlib.h>
#include "add.h"
void add_prog_1(char *host, int num1, int num2) {
CLIENT *clnt;
int *result;
numbers add_1_arg;
clnt = clnt_create(host, ADD_PROG, ADD_VERS, "udp");
if (clnt == NULL) {
clnt_pcreateerror(host);
exit(1);
}
add_1_arg.a = num1;
add_1_arg.b = num2;
result = add_1(&add_1_arg, clnt);
if (result == (int *) NULL) {
clnt_perror(clnt, "call failed");
} else {
printf("Result: %d\n", *result);
}
clnt_destroy(clnt);
}
int main(int argc, char *argv[]) {
char *host;
if (argc < 4) {
printf("Usage: %s <server_host> <num1> <num2>\n", argv[0]);
exit(1);
}
host = argv[1];
int num1 = atoi(argv[2]);
int num2 = atoi(argv[3]);
add_prog_1(host, num1, num2);
return 0;
}

●​ Compile all the files again using the following command: make -f Makefile.add
●​ It will generate all the object files.
●​ Open up two terminals and run the server in one and client in the other.
●​ To start server --> :-$ sudo ./add_server
●​ To start client --> :-$ sudo ./add_client localhost 5 8

OUTPUT:

RESULT:

Client server Implementation using Remote Procedure Protocol has been executed
successfully.

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