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
| #include <sys/types.h> //différentes librairies
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h> /* close() */
#include <string.h> /* memset() */
#define LOCAL_SERVER_PORT 50000
#include <pthread.h>
void *stockage () //fonction stockage
{
int num_enregistrement;
char nom, prenom;
int nb_points;
FILE *fich;
fich=fopen("/home/simon/Bureau/exam.txt","r");
fscanf(fich,"%d %s %s %d", &num_enregistrement , &nom, &prenom, &nb_points);
printf("\nlecture reussi !!!\n");
fclose(fich);
return ((void *)&num_enregistrement);
}
int main(int argc,char * argv[])
{
int sock_ecoute,sock_service,n;
struct sockaddr_in cliAddr, servAddr;
pthread_t thread [5];
socklen_t longueur;
int num_thread = 0;
sock_ecoute= socket(AF_INET, SOCK_STREAM, 0);
memset(&servAddr,0,sizeof(struct sockaddr_in));
servAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Adresse IP automatique */
servAddr.sin_family = AF_INET; /* Protocole familial (IP) */
servAddr.sin_port = htons(LOCAL_SERVER_PORT); /* Listage du port*/
bind(sock_ecoute,(struct sockAddr*) &servAddr,sizeof(servAddr));
listen(sock_ecoute,5);
//boucle infinie
while (1)
{
longueur=sizeof(struct sockaddr_in);
sock_service=accept(sock_ecoute,(struct sockAddr*)&cliAddr,&longueur);
pthread_create(&thread[num_thread],NULL,stockage,&sock_service);
num_thread++;
}
} |
Partager