<commit_before>/**communications clients avec les sockets TCP en C.
* AUTHORS: 
*/
//Si nous sommes sous Windows
#include <winsock2.h>
typedef int socklen_t;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
//#include <conio.h>

#define PORT 20019

void envoie(char *msg, SOCKET sock){
	int taille = (int)strlen(msg)+1;
	if(send(sock, &taille, sizeof(taille), 0) != -1){
		send(sock, msg, taille, 0);
	}
}

char* recoit(SOCKET* sock){
	char *recu; 
	int err, taille;

	err=recv(sock, &taille, sizeof(taille), 0); //la taille des donnees
	if(err != -1){
		recv(sock, recu, sizeof(taille), 0); //reception des donnees
	}
	
		
	

	return res;
}

void interpretor(char *data){
	
}

void* un_client(void * sock){
	char* msg= "";
	do{
		msg = recoit((int) sock);
	}while( strcmp(msg, "EXIT"));

	//fermer la connexion
	printf("fermeture de la socket client\n");
	closesocket(csock);
}


void main(int argc, char **args){
	
	
	WSADATA	WSAData;
  	WSAStartup(MAKEWORD(2,2),&WSAData);
	
	//creation et parametrage du socket
	SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
	SOCKET csock;
	SOCKADDR_IN ssin, ccsin;
	ssin.sin_addr.s_addr = inet_addr("127.0.0.1");
	ssin.sin_family = AF_INET;
	ssin.sin_port = htons(PORT);

  	//code a executer
  	printf("Demarrage du serveur sur le port %d...\n", PORT);	
	
	//etablir une communication
	int err_bind = bind(sock, (SOCKADDR*) &ssin, sizeof(ssin));
	listen(sock, 5);	

	socklen_t taille = sizeof(csin);

	while(true){
		csock = accept(sock, (SOCKADDR*)&ccsin, &taille);

		printf("connexion du client %s:%d...\n", inet_ntoa(ccsin.sin_addr), htons(ccsin.sin_port));

		//creation d'un thread pour gerer le client
		pthread_t client;
		int err_thr = pthread_create(&client, NULL, un_client, (void*) &csock);
<commit_msg>socket<commit_after>/**communications clients avec les sockets TCP en C.
* AUTHORS: 
*/
//Si nous sommes sous Windows
#include <winsock2.h>
typedef int socklen_t;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
//#include <conio.h>

#define PORT 20019

void envoie(char *msg, SOCKET sock){
	int taille = (int)strlen(msg)+1;
	if(send(sock, &taille, sizeof(taille), 0) != -1){
		send(sock, msg, taille, 0);
	}
}

char* recoit(SOCKET* sock){
	char *recu; 
	int err, taille;

	err=recv(sock, &taille, sizeof(taille), 0); //la taille des donnees
	if(err != -1){
		recv(sock, recu, sizeof(taille), 0); //reception des donnees
	}
	
		
	

	return res;
}

void interpretor(char *data){

}

void* un_client(void * sock){
	char* msg= "";
	do{
		msg = recoit((int) sock);
	}while( strcmp(msg, "EXIT"));

	//fermer la connexion
	printf("fermeture de la socket client\n");
	closesocket(csock);
}


void main(int argc, char **args){
	
	
	WSADATA	WSAData;
  	WSAStartup(MAKEWORD(2,2),&WSAData);
	
	//creation et parametrage du socket
	SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
	SOCKET csock;
	SOCKADDR_IN ssin, ccsin;
	ssin.sin_addr.s_addr = inet_addr("127.0.0.1");
	ssin.sin_family = AF_INET;
	ssin.sin_port = htons(PORT);

  	//code a executer
  	printf("Demarrage du serveur sur le port %d...\n", PORT);	
	
	//etablir une communication
	int err_bind = bind(sock, (SOCKADDR*) &ssin, sizeof(ssin));
	listen(sock, 5);	

	socklen_t taille = sizeof(csin);

	while(true){
		csock = accept(sock, (SOCKADDR*)&ccsin, &taille);

		printf("connexion du client %s:%d...\n", inet_ntoa(ccsin.sin_addr), htons(ccsin.sin_port));

		//reception
		system("pwd");
		//creation d'un thread pour gerer le client
		pthread_t client;
		int err_thr = pthread_create(&client, NULL, un_client, (void*) &csock);

{'fraction_non_alphanumeric': 0.1620795107033639, 'fraction_numerical': 0.012788434806783431, 'mean_word_length': 4.229651162790698, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5978204', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1454, 'n_words': 364}