DS(EX-1)
DS(EX-1)
S
22IZ016
EXERCISE-1
AIM:
To implement Client server Implementation using Remote Procedure Protocol.
RPCGEN:
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:
#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
#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;
}
#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.