This commit is contained in:
2025-11-12 18:00:36 +00:00
parent 6805e85f43
commit 58110f7d13
5 changed files with 230 additions and 230 deletions
+5 -5
View File
@@ -44,7 +44,6 @@ int main(int argc, char *argv[])
FILE *file = fopen("received_ugbits.txt", "w");
listen_for_file:
printf("Listening for file chunks...\n");
@@ -55,6 +54,7 @@ int main(int argc, char *argv[])
setsockopt(socket_desc, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
// Listen for file messages from the server
listen_for_file:
while (1)
{
char buffer[CHUNK_SIZE + HEADER_SIZE];
@@ -74,11 +74,11 @@ int main(int argc, char *argv[])
ack_buffer[atoi(chunkNum)] = 1; // Set buffer to RXed
// Method 1: Store chunk in buffer var
memcpy(file_buffer + (atoi(chunkNum) - 1) * CHUNK_SIZE, buffer + HEADER_SIZE, recv_size - HEADER_SIZE);
// memcpy(file_buffer + (atoi(chunkNum) - 1) * CHUNK_SIZE, buffer + HEADER_SIZE, recv_size - HEADER_SIZE);
// Method 2: Write chunk directly to file
// fseek(file, (atoi(chunkNum) - 1) * CHUNK_SIZE, SEEK_SET);
// fwrite(buffer + HEADER_SIZE, 1, recv_size - HEADER_SIZE, file);
fseek(file, (atoi(chunkNum) - 1) * CHUNK_SIZE, SEEK_SET);
fwrite(buffer + HEADER_SIZE, 1, recv_size - HEADER_SIZE, file);
}
}
@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
// If we made it here, the file must be complete.
printf("File transfer complete!\n");
// Method 1: Write entire buffer to file
fwrite(file_buffer, 1, CHUNK_SIZE * TOTAL_CHUNKS, file);
// fwrite(file_buffer, 1, CHUNK_SIZE * TOTAL_CHUNKS, file);
fclose(file);
close(socket_desc);
BIN
View File
Binary file not shown.
+1 -1
View File
File diff suppressed because one or more lines are too long