begin process at 2012 05 27 14:36:34
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Réseaux & Internet

 > CLIENT DE SERVEUR DE CALCUL GRACE AUX PROTOCOLES RPC XDR (EXECUTION DE PROCEDURE A DISTANCE)

CLIENT DE SERVEUR DE CALCUL GRACE AUX PROTOCOLES RPC XDR (EXECUTION DE PROCEDURE A DISTANCE)


 Information sur la source

 Description

Cette application  client serveurillustre l'utilisation des protocoles RPC (remote procedural call) et XDR (external data representation) qui servent à executer une fonctions dans un serveur distant .. le client ne fait qu'envoyer la réf de la fonction et lé argument au serveur qui va lui retourner le résultat ... Nous avons choisi comme exemple des fonction basiques et simples de calcul. PROGRAMME PAR Younes BOUANAN et Yassine CHERKAOUI de l'ECOLE MOHAMMEDIA D'INGENIEURS EMI RABAT/MAROC

Source

  • /////////////////////////////////////////////////////////
  • ////////////////SERVEUR RPC//////////////////////////////
  • //// Par Younes Bouanan et Yassine Cherkaoui ////////////
  • /////////////////////////////////////////////////////////
  • #include<stdio.h>
  • #include<rpc/rpc.h>
  • #include<netdb.h>
  • #include<errno.h>
  • #include<rpc/types.h>
  • #include<rpc/xdr.h>
  • #include <signal.h>
  • /* Definition des constantes */
  • #define PROG 0x20000001 /* numero du programme */
  • #define VERSION 1
  • /* numero de version */
  • #define SOMME 1
  • /* Fonction somme */
  • #define MOYENNE 2
  • /* Fonction moyenne */
  • #define MIN_MAX 3
  • /* Fonction min_max */
  • #define PUISSANCE 4
  • /* Fonction puissance*/
  • #define FACTORIEL 5
  • /* Fonction factoriel*/
  • /* Definition des structures */
  • typedef struct {
  • int entier1;
  • int entier2;
  • } couple_entier;
  • /* Prototype des fonctions */
  • bool_t xdr_couple_entier(XDR *, couple_entier *);
  • couple_entier *fonction_min_max(couple_entier *);
  • int *fonction_moyenne(couple_entier *);
  • int *fonction_somme(couple_entier *);
  • void effacement_service(int);
  • /* Pour traiter la terminaison */
  • //cette fonction efface toute association entre PROG VERSION ET LES PORTS DE LA MACHINE
  • void effacement_service(int sig) {
  • fprintf(stderr,"Effacement du service %d version %d\n",PROG, VERSION);
  • pmap_unset(PROG, VERSION);
  • exit(0);
  • }
  • struct sigaction action;
  • /* Filtre XDR */
  • bool_t xdr_couple_entier(XDR *xdr, couple_entier *entiers) {
  • return(xdr_int(xdr, &entiers->entier1) && xdr_int(xdr, &entiers->entier2));
  • }
  • /* Definition des fonctions de service */
  • //// fonction somme
  • static int somme;
  • int *fonction_somme(couple_entier *entiers) {
  • somme = entiers->entier1 + entiers->entier2;
  • return &somme;
  • }
  • //// fonction qui retourne la moyenne
  • static int moyenne;
  • int *fonction_moyenne(couple_entier *entiers) {
  • moyenne = (entiers->entier1 + entiers->entier2) / 2;
  • return &moyenne;
  • }
  • ////fonction qui retourne une structure Min max
  • static couple_entier min_max; /* min puis max */
  • couple_entier *fonction_min_max(couple_entier *entiers) {
  • if (entiers->entier1 < entiers->entier2) {
  • min_max.entier1 = entiers->entier1;
  • min_max.entier2 = entiers->entier2;
  • }
  • else {
  • min_max.entier1 = entiers->entier2;
  • min_max.entier2 = entiers->entier1;
  • }
  • return &min_max;
  • }
  • ////fontion puissance
  • static int puissance;
  • int *fonction_puissance(couple_entier *entiers){
  • int i;
  • puissance =1;
  • for(i=0;i<entiers->entier2;i++){
  • puissance=puissance*entiers->entier1;
  • }
  • return &puissance;
  • }
  • ////Fonction qui retourne le factoriel
  • static int factoriel;
  • int *fonction_factoriel(couple_entier *entiers){
  • int i;
  • factoriel=entiers->entier1;
  • for(i=1;i<entiers->entier1;i++){
  • factoriel=factoriel*(entiers->entier1-i);
  • }
  • return &factoriel;
  • }
  • /* Programme principal */
  • int main(int argc, char **argv) {
  • /////La structure sigaction décrit le comportement utilisé pour le traitement d'un signal:
  • action.sa_handler= effacement_service;//efface toute association entre PROG VERSION ET LES PORTS DE LA MACHINE
  • sigaction(SIGQUIT, &action, NULL);
  • sigaction(SIGINT, &action, NULL);
  • /////
  • fprintf(stderr, "Mise en place du service RPC %d version %d\n", PROG, VERSION);
  • fprintf(stderr, "Enregistrment des fonctions de services\n");
  • /* Enregistrement des fonctions de service */
  • if (registerrpc(PROG, VERSION, SOMME, fonction_somme, xdr_couple_entier,xdr_int) == -1) {
  • perror("Enregistement de la fonction 1 (somme)\n");
  • }
  • if (registerrpc(PROG, VERSION, MOYENNE, fonction_moyenne, xdr_couple_entier,xdr_int) == -1) {
  • perror("Enregistement de la fonction 2 (moyenne)\n");
  • }
  • if (registerrpc(PROG, VERSION, MIN_MAX, fonction_min_max, xdr_couple_entier,xdr_couple_entier) == -1) {
  • perror("Enregistement de la fonction 3 (min_max)\n");
  • }
  • if (registerrpc(PROG, VERSION, PUISSANCE, fonction_puissance,xdr_couple_entier,xdr_int) == -1) {
  • perror("Enregistrement de la fonction 4 (puissance)\n");
  • }
  • if (registerrpc(PROG, VERSION, FACTORIEL, fonction_factoriel,xdr_couple_entier,xdr_int) == -1) {
  • perror("Enregistrement de la fonction 5 (factoriel)\n");
  • }
  • /* Boucle d’attente */
  • fprintf(stderr, "Lancement de la boucle d’attente\n");
  • svc_run();
  • perror("Erreur dans la boucle d’attente\n");
  • exit(2);
  • }
  • ///////////////////////////////////////////////////////////////////////////////////////////////
  • /////////////////////////////////////////////////////////////
  • ////////Client programme par Younes Bouanan //////////////
  • //////// Yassine Cherkaoui /////////////
  • /////////////////////////////////////////////////////////////
  • #include<stdio.h>
  • #include<rpc/rpc.h>
  • #include<netdb.h>
  • #include<errno.h>
  • #include<rpc/types.h>
  • #include<rpc/xdr.h>
  • #include <signal.h>
  • /* Definition des constantes */
  • #define PROG 0x20000001 /* numero du programme */
  • #define VERSION 1
  • /* numero de version */
  • #define SOMME 1
  • /* Fonction somme */
  • #define MOYENNE 2
  • /* Fonction moyenne */
  • #define MIN_MAX 3
  • /* Fonction min_max */
  • /* Definition des structures */
  • typedef struct {
  • int entier1;
  • int entier2;
  • } couple_entier;
  • /* Prototype des fonctions */
  • bool_t xdr_couple_entier(XDR *, couple_entier *);
  • couple_entier *fonction_min_max(couple_entier *);
  • int *fonction_moyenne(couple_entier *);
  • int *fonction_somme(couple_entier *);
  • /* Filtre XDR */
  • bool_t xdr_couple_entier(XDR *xdr, couple_entier *entiers) {
  • return(xdr_int(xdr, &entiers->entier1) && xdr_int(xdr, &entiers->entier2));
  • }
  • /* Programme principal */
  • int main(int argc, char **argv) {
  • couple_entier entiers, resultats;
  • int numf;
  • int resultat;
  • if (argc != 2) {//on faite rentrer le nom du serveur comme argument
  • perror("Nombre d’argument incorrect\n");
  • exit(1);
  • }
  • //MENU
  • printf("\n\n_____________________________________________\n");
  • printf("**********************************************\n");
  • printf("CLIENT POUR CALCUL GRACE AU PROTOCOLES RPC XDR\n");
  • printf("**********************************************\n");
  • while(1){
  • printf("_____________________________________________\n");
  • printf(" MENU\n");
  • printf("---------------------------------------------\n");
  • printf("|1|SOMME");printf("\t|2|MOYENNE\n");
  • printf("|3|MIN MAX");printf("\t|4|PUISSANCE\n");
  • printf("|5|FACTORIEL\t|0|QUITTER\n");
  • printf("---------------------------------------------\n");
  • do{
  • printf("Entrer le numero de l'operation que vous voullez executer : ");
  • scanf("%d", &numf);
  • if (numf!=0 && numf!=1 && numf!=2 && numf!=3 && numf!=4 && numf!=5){
  • printf("\nAucune operation correspondante\n\n");
  • }
  • }
  • while(numf!=0 && numf!=1 && numf!=2 && numf!=3 && numf!=4 && numf!=5);
  • //FIN DU MENU
  • if (numf==0){
  • exit(2);
  • }
  • /* Initialisation des entiers */
  • if(numf==4){
  • printf("\nEntier1^Entier2\n");
  • }
  • printf("Entier 1 : ");
  • scanf("%d", &(entiers.entier1));
  • if(numf!=5){
  • printf("Entier 2 : ");
  • scanf("%d", &(entiers.entier2));
  • }
  • if (numf != MIN_MAX) {//car min max retourne deux entiers
  • if (callrpc(argv[1], PROG, VERSION, numf, xdr_couple_entier, &entiers, xdr_int, &resultat) != 0) {
  • perror("Appel fonction RPC\n");
  • }
  • printf("==================================================\n");
  • printf("Resultat de l’appel de la fonction %d : %d\n", numf, resultat);
  • printf("==================================================\n");
  • }
  • else {
  • if (callrpc(argv[1], PROG, VERSION, numf, xdr_couple_entier, &entiers, xdr_couple_entier, &resultats) != 0) {
  • perror("Appel fonction RPC\n");
  • }
  • printf("==================================================\n");
  • printf("Resultat de l’appel de la fonction %d :\n", numf);
  • printf("==================================================\n");
  • printf("\t min = %d\n", resultats.entier1);
  • printf("\t max = %d\n", resultats.entier2);
  • printf("==================================================\n");
  • }
  • }
  • }
/////////////////////////////////////////////////////////
////////////////SERVEUR RPC//////////////////////////////
//// Par Younes Bouanan et Yassine Cherkaoui ////////////
/////////////////////////////////////////////////////////
#include<stdio.h>
#include<rpc/rpc.h>
#include<netdb.h>
#include<errno.h>
#include<rpc/types.h>
#include<rpc/xdr.h>
#include <signal.h>
/* Definition des constantes */
#define PROG 0x20000001 /* numero du programme */
#define VERSION 1
/* numero de version */
#define SOMME 1
/* Fonction somme */
#define MOYENNE 2
/* Fonction moyenne */
#define MIN_MAX 3
/* Fonction min_max */
#define PUISSANCE 4
/* Fonction puissance*/
#define FACTORIEL 5
/* Fonction factoriel*/
/* Definition des structures */
typedef struct {
	int entier1;
	int entier2;
	} couple_entier;
/* Prototype des fonctions */
bool_t xdr_couple_entier(XDR *, couple_entier *);
couple_entier *fonction_min_max(couple_entier *);
int *fonction_moyenne(couple_entier *);
int *fonction_somme(couple_entier *);
void effacement_service(int);

/* Pour traiter la terminaison */
//cette fonction efface toute association entre PROG VERSION ET LES PORTS DE LA MACHINE  
void effacement_service(int sig) {
	fprintf(stderr,"Effacement du service %d version %d\n",PROG, VERSION);
	pmap_unset(PROG, VERSION);
	exit(0);
}
struct sigaction action;
/* Filtre XDR */
bool_t xdr_couple_entier(XDR *xdr, couple_entier *entiers) {
	return(xdr_int(xdr, &entiers->entier1) && xdr_int(xdr, &entiers->entier2));
}
/* Definition des fonctions de service */
//// fonction somme
static int somme;
int *fonction_somme(couple_entier *entiers) {
	somme = entiers->entier1 + entiers->entier2;
	return &somme;
}
//// fonction qui retourne la moyenne
static int moyenne;
int *fonction_moyenne(couple_entier *entiers) {
	moyenne = (entiers->entier1 + entiers->entier2) / 2;
	return &moyenne;
}
////fonction qui retourne une structure Min max
static couple_entier min_max; /* min puis max */
couple_entier *fonction_min_max(couple_entier *entiers) {
	if (entiers->entier1 < entiers->entier2) {
		min_max.entier1 = entiers->entier1;
		min_max.entier2 = entiers->entier2;
	}
	 else {
		min_max.entier1 = entiers->entier2;
		min_max.entier2 = entiers->entier1;
	}
	return &min_max;
}
////fontion puissance
static int puissance;
int *fonction_puissance(couple_entier *entiers){
	int i;
	puissance =1;
	for(i=0;i<entiers->entier2;i++){
		puissance=puissance*entiers->entier1;
	}
	return &puissance;
}
////Fonction qui retourne le factoriel
static int factoriel;
int *fonction_factoriel(couple_entier *entiers){
	int i;
	factoriel=entiers->entier1;
	for(i=1;i<entiers->entier1;i++){
		factoriel=factoriel*(entiers->entier1-i);
		}
	return &factoriel;
}

/* Programme principal */
int main(int argc, char **argv) {
/////La structure sigaction décrit le comportement utilisé pour le traitement d'un signal:
	action.sa_handler= effacement_service;//efface toute association entre PROG VERSION ET LES PORTS DE LA MACHINE 
	sigaction(SIGQUIT, &action, NULL);
	sigaction(SIGINT, &action, NULL);
/////
	fprintf(stderr, "Mise en place du service RPC %d version %d\n", PROG, VERSION);
	fprintf(stderr, "Enregistrment des fonctions de services\n");
	/* Enregistrement des fonctions de service */
	if (registerrpc(PROG, VERSION, SOMME, fonction_somme, xdr_couple_entier,xdr_int) == -1) {
		perror("Enregistement de la fonction 1 (somme)\n");
		}
	if (registerrpc(PROG, VERSION, MOYENNE, fonction_moyenne, xdr_couple_entier,xdr_int) == -1) {
		perror("Enregistement de la fonction 2 (moyenne)\n");
		}
	if (registerrpc(PROG, VERSION, MIN_MAX, fonction_min_max, xdr_couple_entier,xdr_couple_entier) == -1) {
		perror("Enregistement de la fonction 3 (min_max)\n");
		}
	if (registerrpc(PROG, VERSION, PUISSANCE, fonction_puissance,xdr_couple_entier,xdr_int) == -1) {
		perror("Enregistrement de la fonction 4 (puissance)\n");
		}
	if (registerrpc(PROG, VERSION, FACTORIEL, fonction_factoriel,xdr_couple_entier,xdr_int) == -1) {
		perror("Enregistrement de la fonction 5 (factoriel)\n");
		}
	/* Boucle d’attente */
	fprintf(stderr, "Lancement de la boucle d’attente\n");
	svc_run();
	perror("Erreur dans la boucle d’attente\n");
	exit(2);
}
///////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////
////////Client programme par Younes Bouanan    //////////////
////////		     Yassine Cherkaoui	/////////////
/////////////////////////////////////////////////////////////

#include<stdio.h>
#include<rpc/rpc.h>
#include<netdb.h>
#include<errno.h>
#include<rpc/types.h>
#include<rpc/xdr.h>
#include <signal.h>
/* Definition des constantes */
#define PROG 0x20000001 /* numero du programme */
#define VERSION 1
/* numero de version */
#define SOMME 1
/* Fonction somme */
#define MOYENNE 2
/* Fonction moyenne */
#define MIN_MAX 3
/* Fonction min_max */
/* Definition des structures */
typedef struct {
int entier1;
int entier2;
} couple_entier;
/* Prototype des fonctions */
bool_t xdr_couple_entier(XDR *, couple_entier *);
couple_entier *fonction_min_max(couple_entier *);

int *fonction_moyenne(couple_entier *);
int *fonction_somme(couple_entier *);
/* Filtre XDR */
bool_t xdr_couple_entier(XDR *xdr, couple_entier *entiers) {
	return(xdr_int(xdr, &entiers->entier1) && xdr_int(xdr, &entiers->entier2));
}
/* Programme principal */
int main(int argc, char **argv) {
	couple_entier entiers, resultats;
	int numf;
	int resultat;
	if (argc != 2) {//on faite rentrer le nom du serveur comme argument
		perror("Nombre d’argument incorrect\n");
		exit(1);
		}
	//MENU
	printf("\n\n_____________________________________________\n");
	printf("**********************************************\n");	
	printf("CLIENT POUR CALCUL GRACE AU PROTOCOLES RPC XDR\n");
	printf("**********************************************\n");
  while(1){
	printf("_____________________________________________\n");	
	printf("                 MENU\n");
	printf("---------------------------------------------\n");		
	printf("|1|SOMME");printf("\t|2|MOYENNE\n");	
	printf("|3|MIN MAX");printf("\t|4|PUISSANCE\n");
	printf("|5|FACTORIEL\t|0|QUITTER\n");
	printf("---------------------------------------------\n");
	do{
		printf("Entrer le numero de l'operation que vous voullez executer : ");
		scanf("%d", &numf);
		if (numf!=0 && numf!=1 && numf!=2 && numf!=3 && numf!=4 && numf!=5){
			printf("\nAucune operation correspondante\n\n");
			}
	}
	while(numf!=0 && numf!=1 && numf!=2 && numf!=3 && numf!=4 && numf!=5);
	//FIN DU MENU
	if (numf==0){
		exit(2);
		}
	/* Initialisation des entiers */
	if(numf==4){
			printf("\nEntier1^Entier2\n");
			}
	printf("Entier 1 : ");
	scanf("%d", &(entiers.entier1));
	if(numf!=5){
		printf("Entier 2 : ");
		scanf("%d", &(entiers.entier2));
		}
	if (numf != MIN_MAX) {//car min max retourne deux entiers
		if (callrpc(argv[1], PROG, VERSION, numf, xdr_couple_entier, &entiers, xdr_int, &resultat) != 0) {
			perror("Appel fonction RPC\n");
			}
		printf("==================================================\n");
		printf("Resultat de l’appel de la fonction %d : %d\n", numf, resultat);
		printf("==================================================\n");
	}
	 else {
		if (callrpc(argv[1], PROG, VERSION, numf, xdr_couple_entier, &entiers, xdr_couple_entier, &resultats) != 0) {
			perror("Appel fonction RPC\n");
			}
		printf("==================================================\n");
		printf("Resultat de l’appel de la fonction %d :\n", numf);
		printf("==================================================\n");
		printf("\t min = %d\n", resultats.entier1);
		printf("\t max = %d\n", resultats.entier2);
		printf("==================================================\n");
		}
	}
}



 Sources du même auteur

APPLICATION DE TRANSFERT DE FICHIERS SOCKET CLIENT SERVEUR U...

 Sources de la même categorie

Source avec Zip Source avec une capture MINI SERVEUR HTTP [WINDOWS] par ganjarasta
Source avec Zip Source avec une capture CLIENT DE TEST MODBUS TCP par brunovan
Source avec Zip Source avec une capture SCANIP [ARP / ICMP] par ganjarasta
Source avec Zip Source avec une capture TRACEROUTE [WINPCAP] par ganjarasta
Source avec Zip SERVEUR MULTITHREAD [LINUX/WIN] par nipepsinicolas

 Sources en rapport avec celle ci

Source avec Zip MINICHAT MULTI-CLIENT par wisar
Source avec Zip Source avec une capture CLIENT/SERVEUR UTILISANT LES IOCP RÉALISÉ AVEC BORLAND BUILD... par goodboy21
Source avec Zip SERVEUR/CLIENT LINUX par ghost4
Source avec Zip KEYLOGGER : SERVEUR/CLIENT (EN MULTI-THREAD) par thesimsone
Source avec Zip Source avec une capture KEYLOGGER SERVEUR/CLIENT par yann2192

Commentaires et avis

Commentaire de karaochi le 26/10/2009 09:12:51

bjr,
merçi pour ta source.dis moi pour la compilation on a besoin encore du fichier.x ou on peut l'executé directement en l'enrregistrant en un fichier.c ?
merçi de me répondre.

Commentaire de assoump44 le 22/03/2010 15:28:29

svp
vous pouvez m'expliquer comment compilé et executé ce code???????

Commentaire de assoump44 le 22/03/2010 16:04:20

j'ai compilé le code mais j'ai trouvé un problème au niveau du client dans le Programme Principal "callrpc" les 4 derniers parametres
erreur: [warning: passing argument 5 of 'callrpc' from incompatible pointer type]
meme erreur pour les paramètres 6,7,8
merci

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Serveur web basé sur le protocole RPC/XDR [ par mouboho ] Bonjourssvp je voudrais developper un serveur web bas&#233; sur rpc/xdr.j'ai besoin d'aide sur ce sujet.toute suggestion est la bien venue merci d'ava un serveur unix configure des client windows avec les rpc [ par oussssa ] &nbsp;bonjour :mon probleme c'est de faire un serveur unix qui va executer des prg ecrite en c# qui controle&nbsp; et configures les @ ip, journal d'e codes sources pour client_serveur en c++ [ par dream1983 ] salut je voudrais savoir le codes source d'une application de client serveur en visual c++ Comment on fait un serveur multi-client avec Winsock 2 [ par Mick7 ] voila je voulais savoir comment on fait un serveur multi-client, si il fallait obligatoirement utiliser des threads, si il fallait creer un socket par Recherche Client/serveur d'mage [ par doberman7578 ] Bonjour &#224;&nbsp; tous,Comme nous pouvons le voir en cherchant sur les source de ce forum, il ni a pas de exemple de client serveur d'image en c++ Chat client serveur C [ par lenneth666 ] Bonjour comme projet je dois faire un chat en C. Mais je ne sais pas du tout par ou commecer. et la m&#233;thode a suivre. problème serveur TCP en C [ par lenneth666 ] Bonjour j'ai essay&#233; de faire un client server TCP en C mais mon serveur bloque a l'instruction suivante : client_socket = accept( ma_socket,(s Deconnection serveur en C [ par lenneth666 ] Bonjour j'ai fais un client serveur avec une connection TCP. J'aimerais savoir comment l'on peut g&#233;rer la d&#233;connection d'un client ? Il y a Problème de sockets... [ par nightlord666 ] Bonjour ! J'essaie en ce moment de programmer un serveur multithread qui servira(peut-&#234;tre) &#224; un projet de MMORPG. Le serveur fonctionne nor client serveur TCP sous unix [ par ossona ] bonjour,je suis vraiment en galere !je n arrive pas a faire un programme client-serveur TCP simple ou il y a seulement un serveur et 3-4 clients pas b


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,030 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales