Ver 2
This commit is contained in:
@@ -44,17 +44,17 @@ int main(int argc, char *argv[])
|
||||
|
||||
FILE *file = fopen("received_ugbits.txt", "w");
|
||||
|
||||
|
||||
printf("Listening for file chunks...\n");
|
||||
|
||||
// Set socket timeout to 5 seconds
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
setsockopt(socket_desc, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
|
||||
|
||||
// Listen for file messages from the server
|
||||
listen_for_file:
|
||||
|
||||
printf("Listening for file chunks...\n");
|
||||
|
||||
// Set socket timeout to 5 seconds
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
setsockopt(socket_desc, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
|
||||
|
||||
// Listen for file messages from the server
|
||||
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);
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user