Winsock recv and fwrite problem

Why when I recive data shorter than the DEFAULT_BUFLEN the program don`t write it to the file?
....
#define DEFAULT_BUFLEN 512
....
printf("sendig %s",someText);
iSendResult = send( sockets, someText, (unsigned)strlen(someText), 0 );
printf("Bytes sent: %d\n", iSendResult);
iSendResult = send( sockets, someText2, sizeof(type), 0 );
FILE * pFile;
pFile = fopen ( "C:\\Users\\0x000FF4\\CommandAndControl_Server\\a.jpg" , "ab" );
do{
char recvbuf[DEFAULT_BUFLEN];
iResult = recv(sockets,recvbuf,recvbuflen,0);

if(iResult == -1)
{
wprintf(L"failed with error: %d\n", WSAGetLastError());
}
fwrite (recvbuf , 1 , iResult , pFile );
printf("\n %d",iResult);
} while(iResult > 0);
fclose (pFile);
....
Take a look at this. It addresses the problem you have.
http://www.cplusplus.com/forum/unices/97612/
Topic archived. No new replies allowed.