Hi there,
I'm putting together a simple client and server to receive packets containing video data. Here is the part where data is read. The data packets contain typically around 1000 - 1500 bytes of data.
int getNoPackets = 0;
int packetsWrittenToFile = 0;
for (i=0; i<NPACK; i++) {
getNoPackets = recvfrom(s, buf, 10000, 0, &si_other, &slen);
if(getNoPackets == -1){
diep("recvfrom()"); }
else{
packetsWrittenToFile = fwrite(buf, 1, getNoPackets, destinationFile);
printf("Received packet number: %i containing %i bytes toFile %i \n", i, getNoPackets, packetsWrittenToFile);
}
When i have a look at the file after the transmission is finished, all data is received correctly except the last portion of the data. I have tried this with both small and large data transfers (12.1kb sent has 12.0kb written in the file and 235kb has 233kb written in the file).
The final print statement also tells me that all packets are received, the number of bytes that the packet contains, and also the amount of data written to the file.
The following is output to the terminal:
Received packet number: 0 containing 13 bytes toFile 13
Received packet number: 1 containing 9 bytes toFile 9
Received packet number: 2 containing 7904 bytes toFile 7904
Received packet number: 3 containing 1239 bytes toFile 1239
Received packet number: 4 containing 1625 bytes toFile 1625
Received packet number: 5 containing 1636 bytes toFile 1636
This says that 13+9+7904+1239+1625+1636 = 12426 bytes were written to the file, whereas in reality only 12288 bytes were written.
Does anyone know the reason behind this?