From 9674422b1e1a2b2213f162ad9f985f22cb9a5d0c Mon Sep 17 00:00:00 2001 From: fanasina Date: Sat, 19 Apr 2025 09:12:58 +0200 Subject: [PATCH] y_socket: try send file, neuron_t: modify EXTRACT from filr to neuron/tensor --- neuron_t/src/neuron_t/neuron_t.c | 2 +- neuron_t/src/neuron_t/nneuron_t_file.h | 190 ++++++++++++++++++++- neuron_t/test/is_good.c | 98 ++++++++++- y_socket_t/include/y_socket_t/y_socket_t.h | 1 + y_socket_t/src/y_socket_t/y_socket_t.c | 186 ++++++-------------- 5 files changed, 333 insertions(+), 144 deletions(-) diff --git a/neuron_t/src/neuron_t/neuron_t.c b/neuron_t/src/neuron_t/neuron_t.c index 28506d7..a1ec512 100644 --- a/neuron_t/src/neuron_t/neuron_t.c +++ b/neuron_t/src/neuron_t/neuron_t.c @@ -635,7 +635,7 @@ void print_weight_in_neurons_##type(neurons_##type *nn, char *msg){\ if(tmp->weight_in){\ sprintf(vmsg,"%s layer %ld",msg,i++);\ print_tensor_msg_##type(tmp->weight_in, vmsg);\ - }\ + }else{printf("weight_in %d NULL\n",i);}\ tmp = tmp->next_layer;\ }\ }\ diff --git a/neuron_t/src/neuron_t/nneuron_t_file.h b/neuron_t/src/neuron_t/nneuron_t_file.h index b37ca24..3a24fd6 100644 --- a/neuron_t/src/neuron_t/nneuron_t_file.h +++ b/neuron_t/src/neuron_t/nneuron_t_file.h @@ -1,6 +1,9 @@ #ifndef NNEURONE_T_FILE_H__C_ #define NNEURONE_T_FILE_H__C_ +#include +#include + #include "neuron_t/neuron_t.h" #include "tensor_t/tensor_t.h" @@ -146,7 +149,7 @@ do{\ \ }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{\ FILE *f_input;\ f_input=fopen(file_name_input,"r");\ @@ -254,5 +257,190 @@ do{\ \ }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; curIninput = |%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!='[') && (jrank)){ \ + 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_ */ diff --git a/neuron_t/test/is_good.c b/neuron_t/test/is_good.c index 90247c8..efd26ec 100644 --- a/neuron_t/test/is_good.c +++ b/neuron_t/test/is_good.c @@ -424,7 +424,7 @@ TEST(Extract_weight_in_neurons){ 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, 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") // 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]; tensor_TYPE_FLOAT * linked_tens = NULL; @@ -465,8 +466,6 @@ TEST(Extract_weight_in_neurons){ } - - TEST(Extract_EXPORT_weight_in_neurons){ bool rec_randomizeInitWeight = randomizeInitWeight; 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(&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") 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); - 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, 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; isize; ++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){ diff --git a/y_socket_t/include/y_socket_t/y_socket_t.h b/y_socket_t/include/y_socket_t/y_socket_t.h index c4e9371..377c738 100644 --- a/y_socket_t/include/y_socket_t/y_socket_t.h +++ b/y_socket_t/include/y_socket_t/y_socket_t.h @@ -4,6 +4,7 @@ #include #include #include +#include #include //#include diff --git a/y_socket_t/src/y_socket_t/y_socket_t.c b/y_socket_t/src/y_socket_t/y_socket_t.c index a99601d..1640f0e 100644 --- a/y_socket_t/src/y_socket_t/y_socket_t.c +++ b/y_socket_t/src/y_socket_t/y_socket_t.c @@ -179,6 +179,9 @@ void *y_pollSocketsFunc(void *arg){ char tempAddr[BUF_SIZE]; int c_af; 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]; // int len_msgRet; for(;;){ @@ -198,7 +201,7 @@ void *y_pollSocketsFunc(void *arg){ (struct sockaddr *)&(node.addr), &(node.addr_len)); if(nread == -1) continue; - + if(buf[nread-1]=='\n') buf[nread-1]='\0'; printf("msg : %s\n",buf); status = getnameinfo((struct sockaddr*)&(node.addr), node.addr_len, host, NI_MAXHOST, service, NI_MAXSERV, NI_NUMERICHOST); @@ -211,46 +214,56 @@ printf("msg : %s\n",buf); if(NULL == search_node_in_list_y_NODE_T(argSock->nodes, node)) push_back_list_y_NODE_T(argSock->nodes, node); + /* //UPPER for(int i=0; i='a') && (buf[i]<='z')) - buf[i]=buf[i]+'A'-'a'; - - //memset(msgRet, 0, BUF_SIZE + NI_MAXHOST + NI_MAXSERV + 100); -// sprintf(msgRet, "from %s:%s =%s",host, service, buf); - -// len_msgRet = strlen(msgRet); - printf("sending response %s :\n",buf); - FOR_LIST_FORM_BEGIN(y_NODE_T, argSock->nodes){ - c_af=(argSock->nodes->current_list->value).addr.ss_family; - //memset(tempAddr, 0, BUF_SIZE); - if(c_af==AF_INET){ - if(NULL == inet_ntop(c_af, - &(GET_IN_type_ADDR(&(argSock->nodes->current_list->value),)), - tempAddr, BUF_SIZE/*(argSock->nodes->current_list->value).addr_len*/)){ - fprintf(stderr, "error inet_ntop v4\n"); - } - }else if(c_af==AF_INET6){ - if(NULL == inet_ntop(c_af, - &(GET_IN_type_ADDR(&(argSock->nodes->current_list->value),6)), - tempAddr, BUF_SIZE /*(argSock->nodes->current_list->value).addr_len*/)){ - fprintf(stderr, "error inet_ntop v6 :errno=%d\n",errno); + 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); + // sprintf(msgRet, "from %s:%s =%s",host, service, buf); + + // len_msgRet = strlen(msgRet); + printf("sending response %s :\n",buf_send); + FOR_LIST_FORM_BEGIN(y_NODE_T, argSock->nodes){ + c_af=(argSock->nodes->current_list->value).addr.ss_family; + //memset(tempAddr, 0, BUF_SIZE); + if(c_af==AF_INET){ + if(NULL == inet_ntop(c_af, + &(GET_IN_type_ADDR(&(argSock->nodes->current_list->value),)), + tempAddr, BUF_SIZE/*(argSock->nodes->current_list->value).addr_len*/)){ + fprintf(stderr, "error inet_ntop v4\n"); + } + }else if(c_af==AF_INET6){ + if(NULL == inet_ntop(c_af, + &(GET_IN_type_ADDR(&(argSock->nodes->current_list->value),6)), + tempAddr, BUF_SIZE /*(argSock->nodes->current_list->value).addr_len*/)){ + fprintf(stderr, "error inet_ntop v6 :errno=%d\n",errno); + } } + + if(sendto(fds[(c_af==AF_INET6)].fd, + buf_send, retread, + /*msgRet, len_msgRet,*/ + 0, + (struct sockaddr*)&((argSock->nodes->current_list->value).addr), + (argSock->nodes->current_list->value).addr_len) != + retread + /*len_msgRet*/ + ){ + fprintf(stderr, "Error sending response to %s\n",tempAddr); + }else + printf("sending response to %s\n",tempAddr); } - - if(sendto(fds[(c_af==AF_INET6)].fd, - buf, nread, - /*msgRet, len_msgRet,*/ - 0, - (struct sockaddr*)&((argSock->nodes->current_list->value).addr), - (argSock->nodes->current_list->value).addr_len) != - nread - /*len_msgRet*/ - ){ - fprintf(stderr, "Error sending response to %s\n",tempAddr); - }else - 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)); @@ -264,107 +277,4 @@ printf("msg : %s\n",buf); #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; - -}