What about a simple way like that: Check for the size of the buffer return, if it is as big as your buffer, read the socket again and append it at the end of the buffer, keep doing that until the size returned is smaller than your buffer. That's the end of the packet! Take a look at the code below: unsigned char *BigBuff = NULL; unsigned char buf[4096]; ULONG size = 4096; ULONG rc = 0; BOOL bMoreData = false; ULONG TotalSize = 0; do { bMoreData = true; memset(&buf[0], 0, 4096); rc = TcpRecv(SocAccepted, buf, size); if ( rc == 0 ) { goto end; } if ( rc == (ULONG)SOCKET_ERROR ) goto end; TotalSize = TotalSize + rc; if ( BigBuff == NULL ) { BigBuff = (unsigned char *) malloc (rc+10); if ( !BigBuff ) return NULL; memcpy(BigBuff, buf, rc); } else { unsigned char *p = NULL; p = (unsigned char *)realloc(BigBuff, TotalSize); if ( !p ) { free( BigBuff ); return NULL; } BigBuff = p; memcpy(&BigBuff[TotalSize-rc], buf, rc); } if ( rc == size ) bMoreData = true; }while(bMoreData); end: return (&BigBuff[0]);