0

this is my server code i want to receive more than 1000000 bytes ,so the data should be splited into many packets so i use loop to receive all data ,if i use like this server always wait for client even client sent all data to server ,my messsage is terminated with "!",so i want to receive untill "!",

do
    {

    iByteCount = recv(GetSocketId(), buffer,MAXRECV,0);

            if ( iByteCount > 0 )
            {
                printf("Bytes received: %d\n",iByteCount);
                 strcat(buf,buffer);
            }
            else if ( iByteCount == 0 )
            {
                   if(strlen(buf)>0)
                   {
                       //do process with received data
                   }
                   else
                  printf("receive failed");
                   break;
            }
            else
                printf("recv failed: ");
                break;

        } while(iByteCount > 0);}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Banfa
0

In the block of your if statement simple check the last character received (or all characters received may be) to see if it is an '!' and if so set a flag that causes the while loop to finish.

iByteCount will only be 0 when the connection is closed so unless part of your process is to close the connection once all the data is recieved processing on that condition will not help.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.