Okay thanks for the formatting! :) Let my try to help.... put the loop around the blocking part (pseudocode):
socket();
bind();
for(;;)
{
recvfrom();
if(ok) ExecuteCommand();
}
closesocket();
Right now the worker thread has no exit condition, you probably want to add one in order to avoid terminating the thread the hard way at application exit. Also have a look at some other issues, e.g. starting from this line
nb_caracters=recvfrom(socket_recevoir,buffer,1515,0,(struct sockaddr*)&information_recevoir,&tempo);
should become something like
int nb_caracters = recvfrom(socket_recevoir, buffer, sizeof(buffer)-1, 0, (struct sockaddr*)&information_recevoir, &tempo);
if(nb_caracters > 0) //data was received and no socket error (return value -1)?
{
buffer[nb_caracters] = 0; //one byte was reserved for terminating Null
ExecuteCommand(buffer, NULL, 0); //lets hope it was a complete package and also not a duplicate
}
Webchat in Europe :java: Now with 26% more Twitter
modified on Monday, April 5, 2010 3:34 PM