There are several ways. An easy way could be by sending i.e. an unsigned long (if has the capacity needed) as the first data. Kind of like this: Sending side unsigned long datalength = imageLength; Send(&datalength, sizeof(unsigned long)); while(moreDataToSend) { send(data); } At the receiving side (assuming that the Read function returns the number of bytes read from the socket): unsigned long receivedDataLength; Read(&receivedDataLength, sizeof(unsigned long)); unsigned long receivedBytes = 0L; while(receivedBytes < receivedDataLength) { receivedBytes += (unsigned long) Read(buffer, sizeof(buffer); // Do something with buffer } If an unsigned long isn't enough, the use some other variable type. Just make sure it's the same on both sides.