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);}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.