y_socket: try send file, neuron_t: modify EXTRACT from filr to neuron/tensor

This commit is contained in:
2025-04-19 09:12:58 +02:00
parent b156cdbf51
commit 9674422b1e
5 changed files with 333 additions and 144 deletions
+1 -1
View File
@@ -635,7 +635,7 @@ void print_weight_in_neurons_##type(neurons_##type *nn, char *msg){\
if(tmp->weight_in){\ if(tmp->weight_in){\
sprintf(vmsg,"%s layer %ld",msg,i++);\ sprintf(vmsg,"%s layer %ld",msg,i++);\
print_tensor_msg_##type(tmp->weight_in, vmsg);\ print_tensor_msg_##type(tmp->weight_in, vmsg);\
}\ }else{printf("weight_in %d NULL\n",i);}\
tmp = tmp->next_layer;\ tmp = tmp->next_layer;\
}\ }\
}\ }\
+189 -1
View File
@@ -1,6 +1,9 @@
#ifndef NNEURONE_T_FILE_H__C_ #ifndef NNEURONE_T_FILE_H__C_
#define NNEURONE_T_FILE_H__C_ #define NNEURONE_T_FILE_H__C_
#include <unistd.h>
#include <fcntl.h>
#include "neuron_t/neuron_t.h" #include "neuron_t/neuron_t.h"
#include "tensor_t/tensor_t.h" #include "tensor_t/tensor_t.h"
@@ -146,7 +149,7 @@ do{\
\ \
}while(0); }while(0);
#define EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(type, neuronDst, attribute, file_name_input) \ #define __EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(type, neuronDst, attribute, file_name_input) \
do{\ do{\
FILE *f_input;\ FILE *f_input;\
f_input=fopen(file_name_input,"r");\ f_input=fopen(file_name_input,"r");\
@@ -254,5 +257,190 @@ do{\
\ \
}while(0); }while(0);
#define EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(type, neuronDst, attribute, file_name_input) \
do{\
int fd_input;\
fd_input=open(file_name_input, O_RDONLY);\
if ( fd_input == -1 ) {\
fprintf( stderr, "Cannot open file: %s for reading\n",file_name_input );\
exit( -1 );\
}\
size_t buf_size=820;/*need to be more than the nb of char representation of the type*/\
char *input=malloc(buf_size + 1);\
char *recInput=malloc(buf_size + 1);\
memset(recInput,0, buf_size + 1);\
char *iinput=malloc(buf_size * 2);\
bool size_unknown=false, broken=false; \
bool Done=false;\
int retread = 0, curIn=0, lastNonNumber=0, lenRecIn=0;\
\
list_perm_in_dim *l_p=NULL;\
dimension *dim=NULL;\
size_t ss;\
char *ttmp=NULL;\
char *ppEnd=NULL;\
bool bracketsDown=false, endTensor = false;\
size_t j=0;\
neurons_##type * tmpNN = neuronDst;\
tensor_##type * T=NULL;\
while(tmpNN /*&& !endTensor*/){\
bracketsDown = false;\
Done = false;\
/* T = tmpNN->attribute;\
if(T == NULL){\
Done = true;\
}*/\
T = tmpNN->attribute;\
while((T == NULL) && (tmpNN!=NULL)){\
tmpNN = tmpNN->next_layer;\
if(tmpNN)\
T = tmpNN->attribute;\
}\
/*printf("debug : dd ttmp = %s, T == NULL?=%d %s\n",ttmp,(T==NULL),#attribute);*/\
if(T == NULL){\
Done = true;\
} \
j=0;\
while(!Done /*&& !endTensor*/){\
if(ttmp == NULL || *ttmp=='\0'){\
for(curIn=0; curIn<lenRecIn; ++curIn){\
iinput[curIn]=recInput[lenRecIn-curIn-1];\
}\
retread = read(fd_input, input, buf_size) ;\
endTensor = (retread != buf_size);\
/*printf("debug: ************************* ------>input = |%s|, retread=%d, input[ret-1]={%c}\n", input,retread,input[retread-1]);*/\
lenRecIn = 0;\
for(lastNonNumber=retread-1; lastNonNumber>=0; --lastNonNumber){ \
if(((input[lastNonNumber] >='0') && (input[lastNonNumber] <='9'))||(input[lastNonNumber] =='-')||(input[lastNonNumber] =='.')||(input[lastNonNumber] =='E')||(input[lastNonNumber] =='e')){\
recInput[lenRecIn++]=input[lastNonNumber];\
}\
else break; \
}\
recInput[lenRecIn]='\0';\
/*printf("recInput = |%s|\n", recInput);*/\
for(int ii=0; ii<=lastNonNumber; ++ii){\
iinput[curIn++]=input[ii];\
}\
\
iinput[curIn]='\0';\
/*printf("iinput = |%s|\nDone=%d\n", iinput,Done);*/\
ttmp=iinput;\
}\
while(!Done && (*ttmp != '\0') /*&& !endTensor*/){\
/*printf("debug : >> ttmp = %s, bracketsDown=%d\n",ttmp, bracketsDown);*/\
if(*ttmp=='[') {\
bracketsDown=false;\
}\
ppEnd=ttmp;\
if( !bracketsDown){\
while(*ttmp!='\0' && *ppEnd!=']' ){\
if(*ttmp=='['){\
/*printf("debug : [[ ttmp = %s\n",ttmp);\
if(dim)printDebug_dimension(dim,"[DIM]");*/\
if(l_p != NULL){\
free_dimension(dim);\
free_list_perm_in_dim(l_p);\
l_p=NULL;\
}\
/*if(dim)printDebug_dimension(dim,"{DIM}");*/\
}\
ss = strtoul(ttmp, &ppEnd, 10);\
while(ttmp == ppEnd && *ttmp!='\0' && ppEnd[0] !=']'){\
\
if(*ttmp=='['){\
/*printf("debug : [[ ttmp = %s\n",ttmp);\
if(dim)printDebug_dimension(dim,"[DIM]");*/\
if(l_p != NULL){\
free_dimension(dim);\
free_list_perm_in_dim(l_p);\
l_p=NULL;\
}\
/*if(dim)printDebug_dimension(dim,"{DIM}");*/\
}\
\
/*printf("debug : aa ttmp = %s\n",ttmp);*/\
ttmp++;\
ss = strtoul(ttmp, &ppEnd, 10);\
/*printf("debug : bb ttmp = %s\n",ttmp);*/\
}\
if(ppEnd !=ttmp ){\
append_in_list_perm(&l_p,ss);\
}\
ttmp=ppEnd;\
}\
/*printf("debug : cc ttmp = %s\n",ttmp);*/\
if( *ttmp ==']'){\
dim=create_dim_from_list_perm(l_p);\
bracketsDown = true;\
j=0;\
\
}\
\
}\
/*printf("debug : <<---->> ttmp = %s, bracketsDown=%d T==NULL? =%d, done?=%d\n",ttmp, bracketsDown, (T==NULL), Done);*/\
if(!Done && bracketsDown){\
/*printf("debug : ee ttmp = %s, T==NULL ? = %d\n %ld vs %ld\n",ttmp,(T==NULL),T->dim->rank,dim->rank);\
printDebug_dimension(dim," DIM");*/\
if((T->dim->rank == dim->rank)){\
\
\
\
type x;\
while(strlen(ttmp) && (*ttmp!='[') && (j<dim->rank)){ \
x = strto_##type(ttmp, &ppEnd);\
while(ttmp == ppEnd && strlen(ttmp) && *ttmp!='[' ){\
/*printf("debug : dd ttmp = %s\n",ttmp);*/\
ttmp++;\
x = strto_##type(ttmp, &ppEnd);\
/*printf("debug : ww ttmp = %s\n",ttmp);*/\
}\
if((*ttmp!='[') && (ttmp != ppEnd)){\
T->x[j++]=x;\
/*printf("debug : x=%lf ===> %d\n",x,(j==dim->rank));*/\
}\
else if ( *ttmp =='[') {\
bracketsDown = false;\
Done=true;\
break;\
}\
ttmp=ppEnd;\
Done=(j==dim->rank);\
endTensor=(j==dim->rank);\
}\
if(Done) break;\
if(j == dim->rank ){\
Done = true;\
}\
}else {\
/*endTensor = true;*/\
/*Done = true;\
bracketsDown = false;*/\
break;\
}\
}\
if(Done){\
/*printf("debug : done=%d , l_p==NULL?=%d, endTensor=%d\n",Done, (l_p==NULL), endTensor);*/\
if(l_p != NULL){\
free_dimension(dim);\
free_list_perm_in_dim(l_p);\
l_p=NULL;\
}\
}\
\
}\
if(Done) break;\
\
}\
tmpNN = tmpNN->next_layer;\
}\
free(input);\
free(iinput);\
free(recInput);\
close(fd_input);\
\
}while(0);
#endif /* NNEURONE_T_FILE_H__C_ */ #endif /* NNEURONE_T_FILE_H__C_ */
+94 -4
View File
@@ -424,7 +424,7 @@ TEST(Extract_weight_in_neurons){
size_t reps = 1;// learning_online2_neurons_TYPE_FLOAT(bn,ds,cond); size_t reps = 1;// learning_online2_neurons_TYPE_FLOAT(bn,ds,cond);
EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_bn_weight_in__toExtract.txt") //EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_bn_weight_in__toExtract.txt")
setup_all_layers_functions_TYPE_FLOAT(cpyn, setup_all_layers_functions_TYPE_FLOAT(cpyn,
tensorContractnProdThread_TYPE_FLOAT, tensorContractnProdThread_TYPE_FLOAT,
@@ -438,6 +438,7 @@ TEST(Extract_weight_in_neurons){
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, cpyn, weight_in, ".ff_bn_weight_in__toExtract.txt") EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, cpyn, weight_in, ".ff_bn_weight_in__toExtract.txt")
// copy_weight_in_neurons_TYPE_FLOAT(cpyn, bn); // copy_weight_in_neurons_TYPE_FLOAT(cpyn, bn);
EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_bn_weight_in__toExtract___exp.txt")
char msg[256]; char msg[256];
tensor_TYPE_FLOAT * linked_tens = NULL; tensor_TYPE_FLOAT * linked_tens = NULL;
@@ -465,8 +466,6 @@ TEST(Extract_weight_in_neurons){
} }
TEST(Extract_EXPORT_weight_in_neurons){ TEST(Extract_EXPORT_weight_in_neurons){
bool rec_randomizeInitWeight = randomizeInitWeight; bool rec_randomizeInitWeight = randomizeInitWeight;
randomizeInitWeight =false; randomizeInitWeight =false;
@@ -481,6 +480,7 @@ TEST(Extract_EXPORT_weight_in_neurons){
setup_networks_alloutputs_config_TYPE_FLOAT(&bn,pconf,false,0,1,5000); setup_networks_alloutputs_config_TYPE_FLOAT(&bn,pconf,false,0,1,5000);
setup_networks_alloutputs_config_TYPE_FLOAT(&cpyn, pconf,false,0,1,5000); setup_networks_alloutputs_config_TYPE_FLOAT(&cpyn, pconf,false,0,1,5000);
//print_weight_in_neurons_TYPE_FLOAT(bn, "");
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_target_20240717_01h43m41s_13300.txt") EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_target_20240717_01h43m41s_13300.txt")
setup_all_layers_functions_TYPE_FLOAT(bn, setup_all_layers_functions_TYPE_FLOAT(bn,
@@ -495,7 +495,8 @@ TEST(Extract_EXPORT_weight_in_neurons){
size_t reps = 1;// learning_online2_neurons_TYPE_FLOAT(bn,ds,cond); size_t reps = 1;// learning_online2_neurons_TYPE_FLOAT(bn,ds,cond);
EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_bn_weight_in__toCMP.txt") EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_FLOAT, bn, weight_in, ".ff_bn_weight_in__toCMP__.txt")
print_weight_in_neurons_TYPE_FLOAT(bn, "");
setup_all_layers_functions_TYPE_FLOAT(cpyn, setup_all_layers_functions_TYPE_FLOAT(cpyn,
tensorContractnProdThread_TYPE_FLOAT, tensorContractnProdThread_TYPE_FLOAT,
@@ -538,6 +539,95 @@ TEST(Extract_EXPORT_weight_in_neurons){
double doubleL(double t, double o){
return (o - t) * (o - t)/2;
}
double doubleDL(double t, double o){
return (o - t);
}
double doublef(double x){
return 1/(1+exp((double)(-x)));
}
double doubledf(double x){
return exp(-x)/ ((1+exp(-x)) * (1+exp(-x)));
}
TEST(Extract_EXPORT_weight_in_neurons_double){
bool rec_randomizeInitWeight = randomizeInitWeight;
randomizeInitWeight =false;
data_set_TYPE_DOUBLE *ds= fill_data_set_from_file_TYPE_DOUBLE("xor.txt",1);
// print_data_set_msg_TYPE_DOUBLE(ds,"data");
//config_layers *pconf = create_config_layers_from_OneD(3,(size_t[]){2,4,1}); /* 2 input , 1 target; 1 hidden layer with 5 neurons */
config_layers *pconf = create_config_layers_from_OneD(4,(size_t[]){3,24,24,3});
neurons_TYPE_DOUBLE *bn=NULL, *tmp ;
neurons_TYPE_DOUBLE *cpyn=NULL;
//setup_networks_alloutputs_config_GLOBAL_rdm01_TYPE_DOUBLE(setup_networks_alloutputs_config_TYPE_DOUBLE(&bn,pconf);bn,pconf);
setup_networks_alloutputs_config_TYPE_DOUBLE(&bn,pconf,false,0,1,5000);
setup_networks_alloutputs_config_TYPE_DOUBLE(&cpyn, pconf,false,0,1,5000);
EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_DOUBLE, bn, weight_in, ".ff_target_20240717_01h43m41s_13300.txt")
setup_all_layers_functions_TYPE_DOUBLE(bn,
tensorContractnProdThread_TYPE_DOUBLE,
tensorProdThread_TYPE_DOUBLE,
doubleDL,
doubleL,
doublef,
doubledf);
setup_all_layers_params_TYPE_DOUBLE(bn, 5, 1 , 0.1);
size_t reps = 1;// learning_online2_neurons_TYPE_DOUBLE(bn,ds,cond);
// EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_DOUBLE, bn, weight_in, ".ff_bn_weight_in__toCMP__.txt")
print_weight_in_neurons_TYPE_DOUBLE(bn, "");
setup_all_layers_functions_TYPE_DOUBLE(cpyn,
tensorContractnProdThread_TYPE_DOUBLE,
tensorProdThread_TYPE_DOUBLE,
doubleDL,
doubleL,
doublef,
doubledf);
setup_all_layers_params_TYPE_DOUBLE(cpyn, 5, 1 , 0.1);
// EXTRACT_FILE_TO_TENSOR_ATTRIBUTE_NNEURONS(TYPE_DOUBLE, cpyn, weight_in, ".ff_bn_weight_in__toExtract.txt")
// copy_weight_in_neurons_TYPE_DOUBLE(cpyn, bn);
char msg[256];
tensor_TYPE_DOUBLE * linked_tens = NULL;
for(size_t i=0; i<ds->size; ++i){
// print_predict_by_network_with_error_neurons_TYPE_DOUBLE(bn,ds->input[i],ds->target[i]);
// print_predict_by_network_with_error_neurons_TYPE_DOUBLE(cpyn,ds->input[i],ds->target[i]);
calculate_output_by_network_neurons_TYPE_DOUBLE(bn,ds->input[i],&linked_tens);
sprintf(msg," output base %ld ",i);
print_tensor_msg_TYPE_DOUBLE(linked_tens,msg);
calculate_output_by_network_neurons_TYPE_DOUBLE(cpyn,ds->input[i],&linked_tens);
sprintf(msg," output copy %ld ",i);
print_tensor_msg_TYPE_DOUBLE(linked_tens,msg);
}
// EXPORT_TO_FILE_TENSOR_ATTRIBUTE_IN_NNEURONS(TYPE_DOUBLE, cpyn, weight_in, ".ff_bn_weight_in__exportedCPYfromExtract.txt")
free_data_set_TYPE_DOUBLE(ds);
free_neurons_TYPE_DOUBLE(bn);
free_neurons_TYPE_DOUBLE(cpyn);
LOG("reps = %ld\n",reps);
randomizeInitWeight = rec_randomizeInitWeight;
}
int main(int argc, char **argv){ int main(int argc, char **argv){
@@ -4,6 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <string.h> #include <string.h>
//#include <sys/socket.h> //#include <sys/socket.h>
+18 -108
View File
@@ -179,6 +179,9 @@ void *y_pollSocketsFunc(void *arg){
char tempAddr[BUF_SIZE]; char tempAddr[BUF_SIZE];
int c_af; int c_af;
char host[NI_MAXHOST], service[NI_MAXSERV]; char host[NI_MAXHOST], service[NI_MAXSERV];
char buf_send[BUF_SIZE];
int fd_file;
int retread;
// char msgRet[BUF_SIZE + NI_MAXHOST + NI_MAXSERV + 100]; // char msgRet[BUF_SIZE + NI_MAXHOST + NI_MAXSERV + 100];
// int len_msgRet; // int len_msgRet;
for(;;){ for(;;){
@@ -198,7 +201,7 @@ void *y_pollSocketsFunc(void *arg){
(struct sockaddr *)&(node.addr), &(node.addr_len)); (struct sockaddr *)&(node.addr), &(node.addr_len));
if(nread == -1) if(nread == -1)
continue; continue;
if(buf[nread-1]=='\n') buf[nread-1]='\0';
printf("msg : %s\n",buf); printf("msg : %s\n",buf);
status = getnameinfo((struct sockaddr*)&(node.addr), node.addr_len, host, NI_MAXHOST, service, NI_MAXSERV, NI_NUMERICHOST); status = getnameinfo((struct sockaddr*)&(node.addr), node.addr_len, host, NI_MAXHOST, service, NI_MAXSERV, NI_NUMERICHOST);
@@ -211,16 +214,24 @@ printf("msg : %s\n",buf);
if(NULL == search_node_in_list_y_NODE_T(argSock->nodes, node)) if(NULL == search_node_in_list_y_NODE_T(argSock->nodes, node))
push_back_list_y_NODE_T(argSock->nodes, node); push_back_list_y_NODE_T(argSock->nodes, node);
/*
//UPPER //UPPER
for(int i=0; i<nread; ++i) for(int i=0; i<nread; ++i)
if((buf[i] >='a') && (buf[i]<='z')) if((buf[i] >='a') && (buf[i]<='z'))
buf[i]=buf[i]+'A'-'a'; buf[i]=buf[i]+'A'-'a';*/
fd_file = open( buf , O_RDONLY);
if(fd_file == -1){
fprintf(stderr,"error opening file |%s| for reading\n",buf);
return NULL;
}
while((retread = read(fd_file, buf_send, BUF_SIZE) ) > 0 )
{
//memset(msgRet, 0, BUF_SIZE + NI_MAXHOST + NI_MAXSERV + 100); //memset(msgRet, 0, BUF_SIZE + NI_MAXHOST + NI_MAXSERV + 100);
// sprintf(msgRet, "from %s:%s =%s",host, service, buf); // sprintf(msgRet, "from %s:%s =%s",host, service, buf);
// len_msgRet = strlen(msgRet); // len_msgRet = strlen(msgRet);
printf("sending response %s :\n",buf); printf("sending response %s :\n",buf_send);
FOR_LIST_FORM_BEGIN(y_NODE_T, argSock->nodes){ FOR_LIST_FORM_BEGIN(y_NODE_T, argSock->nodes){
c_af=(argSock->nodes->current_list->value).addr.ss_family; c_af=(argSock->nodes->current_list->value).addr.ss_family;
//memset(tempAddr, 0, BUF_SIZE); //memset(tempAddr, 0, BUF_SIZE);
@@ -239,12 +250,12 @@ printf("msg : %s\n",buf);
} }
if(sendto(fds[(c_af==AF_INET6)].fd, if(sendto(fds[(c_af==AF_INET6)].fd,
buf, nread, buf_send, retread,
/*msgRet, len_msgRet,*/ /*msgRet, len_msgRet,*/
0, 0,
(struct sockaddr*)&((argSock->nodes->current_list->value).addr), (struct sockaddr*)&((argSock->nodes->current_list->value).addr),
(argSock->nodes->current_list->value).addr_len) != (argSock->nodes->current_list->value).addr_len) !=
nread retread
/*len_msgRet*/ /*len_msgRet*/
){ ){
fprintf(stderr, "Error sending response to %s\n",tempAddr); fprintf(stderr, "Error sending response to %s\n",tempAddr);
@@ -252,6 +263,8 @@ printf("msg : %s\n",buf);
printf("sending response to %s\n",tempAddr); printf("sending response to %s\n",tempAddr);
} }
} }
close(fd_file);
}
} }
// printf("nread = %ld: buf=%s\nlen_buf=%ld\ncmp=%d\n",nread,buf,strlen(buf),strncmp(buf,"SHUTDOWN SERVER",15)); // printf("nread = %ld: buf=%s\nlen_buf=%ld\ncmp=%d\n",nread,buf,strlen(buf),strncmp(buf,"SHUTDOWN SERVER",15));
if(strncmp(buf,"SHUTDOWN SERVER",15) == 0){ if(strncmp(buf,"SHUTDOWN SERVER",15) == 0){
@@ -264,107 +277,4 @@ printf("msg : %s\n",buf);
#define xstr(x) str(x) #define xstr(x) str(x)
void *threadFuncSend(void *arg){
struct argdst * dstarg = (struct argdst*)arg;
int socketDescriptor, status;
unsigned int msgLength;
struct addrinfo hints, *serverInfo, *p;
struct timeval timeValue;
fd_set readSetFD;
char msg[BUF_SIZE];//, serverPort[PORT_ARRAY_SIZE];
bool sockSuccess = false;
/*
puts("Entrez le nom du serveur ou son adresse IP : ");
memset(msg, 0, sizeof msg);
scanf("%s"xstr(BUF_SIZE)"s",msg);
puts("Entrez le numéro de port du serveur : ");
memset(serverPort, 0, sizeof serverPort);
scanf("%s"xstr(MAX_PORT)"s",serverPort);
*/
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
if((status = getaddrinfo(dstarg->addrStr, dstarg->port, &hints, &serverInfo)) != 0){
fprintf(stderr, "getaddrinfo: %s\n",gai_strerror(status));
exit(EXIT_FAILURE);
}
p = serverInfo;
while((p!=NULL) && !sockSuccess){
if(p->ai_family == AF_INET)
puts("Open IPv4 socket");
else
puts("Open IPv6 socket");
if((socketDescriptor = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1){
perror("socket:");
sockSuccess = false; // echec ouverture du socket
p = p->ai_next;
}
else
sockSuccess = true;
}
freeaddrinfo(serverInfo);
if(p==NULL){
fputs("Creation de socket impossible", stderr);
return NULL;
}
puts("\n Entrez quelques caractères au clavier.");
puts("Le serveur les modifiera et les renvera.");
puts("Pour sortir, entrez une ligne avec le caractère '.' uniquement.");
puts("Saisie du message : ");
memset(msg, 0, sizeof msg);
scanf(" %"xstr(BUF_SIZE)"[^\n]%*c", msg);
while(strcmp(msg, ".")){
if((msgLength = strlen(msg)) > 0 ){
if(sendto(socketDescriptor, msg, msgLength, 0,
p->ai_addr, p->ai_addrlen) == -1){
perror("sendto:");
close(socketDescriptor);
exit(EXIT_FAILURE);
}
FD_ZERO(&readSetFD);
FD_SET(socketDescriptor, &readSetFD);
timeValue.tv_sec = 1;
timeValue.tv_usec = 0;
if(select(socketDescriptor +1, &readSetFD, NULL,NULL, &timeValue)){
memset(msg, 0, sizeof msg);
if(recv(socketDescriptor, msg, sizeof msg, 0) == -1){
perror("recv:");
close(socketDescriptor);
exit(EXIT_FAILURE);
}
printf("Message traité : %s\n", msg);
if(strcmp(msg,"SHUTDOWN SERVER")==0)
break;
}
else{
puts("Pas de réponse dans la seconde.");
}
}
puts("Saisie du message : ");
memset(msg, 0, sizeof msg);
scanf(" %"xstr(BUF_SIZE)"[^\n]%*c", msg);
}
close(socketDescriptor);
return NULL;
}