C Program to Client That Calls The Remote Procedure

Write a C Program to Client That Calls The Remote Procedure ?


Solution:

//La Spada Cristina 0000669010


/* RPC_Client.c: client che chiama la procedura remota */

#include <stdio.h>
#include <rpc/rpc.h>
#include "RPC_xFile.h"

#define COMMAND_SIZE 20

main(int argc, char *argv[]){

CLIENT *cl;
int num;
char *server, *stringa_op1;
char buffer[COMMAND_SIZE], c;
int *risultato_op2; //serve come risultato della funzione in .x che mi restituisce un int

Struttura1 *struttura1;

if (argc < 2) {
fprintf(stderr, "Usage: %s <serverhost>\n", argv[0]);
exit(1);
}
server = argv[1];


cl = clnt_create(server, FILEX, FILEVERS, "udp");

if (cl == NULL) {
clnt_pcreateerror(server);
exit(2);
}

stringa_op1 = (char *)malloc(strlen(buffer) + 1);

do{
printf("\nChe operazione vuoi fare? (A:visualizza dettagli volo, B: elimina volo o uscire) "); 
gets(buffer);


if (buffer == NULL) {
break;
}
else if (strcmp(buffer, "A") == 0) {
printf("inserire id volo: \n");
gets(stringa_op1);
struttura1 = visualizza_dati_1(&stringa_op1, cl); 

if (struttura1->error == -1)
{
printf("l'id non esiste\n");
exit(3);
}
else
{
printf("Trovato volo: \nid: %s\nnumero: %s\norario: %s\npasseggero: %s\ngate: %s\n\n", struttura1->id, struttura1->numero, struttura1->ora, struttura1->nome, struttura1->gate);
}//operazione1

else if (strcmp(buffer, "A") == 0) {
printf("Inserisci id volo da cancellare: ");
gets(stringa_op1);

risultato_op2 = elimina_volo_1(&stringa_op1, cl);
if (risultato_op2== -1)
{
printf("errore nella eliminazione\n");
exit(4);

}
else
{
printf("Eliminazione effettuata correttamente\n");
}
}//operazione2
}while(buffer != NULL && strcmp(buffer, "uscire") != 0);


// Libero le risorse distruggendo il gestore di trasporto
free(stringa_op1);

clnt_destroy(cl);
printf("\nRPC_Client Termino...\n");
exit(0);
}


Learn More :