Bonsoir,
Avant tout je veux féliciter les modérateurs de ce site, que je trouve vraiment trés trés bien.
pour mon problème, voila:
j'essaye de faire une application client-serveur: un processus client qui demande soit résévation, soit consultation des place libre pour un événement(ex:film au cinéma). et un processus(pére-fils) serveur qui repond aux demandes des clients.
je commancer avec le processus client et voila ce que j'ai fais:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
 
[#include<errno.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
 
 
#define PORTC 5000
#define PORTS1 5100
#define PORTS2 5200
 
main(void){
int sock;
struct hostent *h;
struct sockaddr_in sockin;
char evenement[50];
char type;
char placelibre[10];
socklen_t lg;
int n;
for( ; ; ){
	printf("Pour fermer le programme , tapper ctrl+c .\n");
	printf("entrer le identité de l'événement completé par la date: \n EX:spiderman3 1/12/08.\n");
	fget(evenement,sizeof(evenement),stdin);
 
	printf("que vouller vous faire :\n tapper 'R' pour reservation, ou tapper 'C' pour consultation.\n");
	fget(type,1,stdin);
 
/*consultation*/
	if(type=='c'){
		/*creation de socket*/
 
		if((sock = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP))<0)
		{
		perror("erreur de creation socket");
		exit(1);	
		};
/* mise a zero de la zone memoire d'adresse */
 
	bzero(&sockin, sizeof(sockin));
 
/* preparation de la structure adresse*/
 
	sockin.sin_family=AF_INET;
	sockin.sin_port =htons(PORTC); 
	sockin.sin_addr.s_addr=INADDR_ANY; /*b n'import quelle adresse*/
 
/*attachment socket*/
 
	if( bind(sock,(struct sockaddr *)&sockin, sizeof(sockin))<0) {
	perror("Erreur d'attachement: appel BIND");
	exit (2);
	}
 
	if(!(h=gethostbyname("localhost")))  {
		perror("erreur gethostbyname");
		exit(3);
	}
	bzero(&sockin, sizeof(sockin));
	sockin.sin_family = AF_INET;
	memcpy(&sockin.sin_addr,h->h_addr,h->h_length);
	sockin.sin_port= htons(PORTS1);
 
 
	sendto(sock,evenement,50,0,(struct sockaddr *)&sockin,sizeof(sockin));
	n=recvfrom(sock,placelibre,1,0,(struct sockaddr *)&sockin, sizeof(sockin));
 
	if(strncmp(placelibre,"erreur !!",n-1)==0)
	printf("desolé, cette evenement n'existe pas \n");
 
	else	{
		if(strncmp(placelibre,"réservation accépté !",n-1)==0)
			printf("désolé, cette événement n'éxiste pas \n");
 
		else
			printf("erreur inconu!!");
		}
	close (sock);
 
	}
 
/*reservation*/
	if(type=='R')
	{
 
	/*creation de socket*/
 
	if((sock = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP))<0)
		{
		perror("erreur de creation socket");
		exit(1);	
		};
/* mise a zero de la zone memoire d'adresse */
 
	bzero(&sockin, sizeof(sockin));
 
/* preparation de la structure adresse*/
 
	sockin.sin_family=AF_INET;
	sockin.sin_port =htons(PORTC);
	sockin.sin_addr.s_addr=INADDR_ANY; /*b n'import quelle adresse*/
 
/*attachment socket*/
 
	if( bind(sock,(struct sockaddr *)&sockin, sizeof(sockin))<0) {
		perror("Erreur d'attachement: appel BIND");
		exit (2);
		}
 
	if(!(h=gethostbyname("localhost")))  {
		perror("erreur gethostbyname");
		exit(3);
		}
	bzero(&sockin, sizeof(sockin));
	sockin.sin_family = AF_INET;
	memcpy(&sockin.sin_addr,h->h_addr,h->h_length);
	sockin.sin_port= htons(PORTS2);
 
	sendto (sock,evenement,50,0,(struct sockaddr *)&sockin, sizeof(sockin));
	n=recvfrom(sock,placelibre,10,0,(struct sockaddr *)&sockin, sizeof(sockin));
 
	if(strncmp(placelibre,"erreur !!",n-1)==0)
		printf("desolé, cette evenement n'existe pas \n");
 
	else	{
		if(strncmp(placelibre,"réservation accépté !",n-1)==0)
			printf("désolé, cette événement n'éxiste pas \n");
 
		else
			printf("erreur inconu!!");
		}
	close (sock);
 
	}
	else printf("erreur de frappe, redemarer le programme!");
}
}
peut être vous allez trouver que c'est pas assez professionnelle, c'est que je ne suis qu'un débutant: oops:

après la compilation je trouve :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11

[xxx@localhost ~]$ gcc -o clien client.c
client.c: In function ‘main’:
client.c:73: attention : passing argument 6 of ‘recvfrom’ makes pointer from integer without a cast
client.c:129: attention : passing argument 6 of ‘recvfrom’ makes pointer from integer without a cast
/tmp/cckM7zJU.o: In function `main':
client.c: (.text+0x48): undefined reference to `fget'
client.c: (.text+0x71): undefined reference to `fget'
collect2: ld a retourné 1 code d'état d'exécution
[xxx@localhost ~]$
j'ai essayer de chercher moi même sur le net , mais sans résultat, si qq peux me fournir une indication ca sera plusque génial. merci d'avance