53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <arpa/inet.h>
|
|
#include <sys/socket.h>
|
|
|
|
#define PORT 8081
|
|
#define SERVER_IP "127.0.0.1"
|
|
#define BUFFER_SIZE 4096
|
|
#define TARGET_MB 100
|
|
|
|
int main() {
|
|
int sock = 0;
|
|
struct sockaddr_in serv_addr;
|
|
char buffer[BUFFER_SIZE];
|
|
memset(buffer, 'A', BUFFER_SIZE); // Dummy data
|
|
|
|
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
|
printf("\n Socket creation error \n");
|
|
return -1;
|
|
}
|
|
|
|
serv_addr.sin_family = AF_INET;
|
|
serv_addr.sin_port = htons(PORT);
|
|
|
|
if (inet_pton(AF_INET, SERVER_IP, &serv_addr.sin_addr) <= 0) {
|
|
printf("\nInvalid address/ Address not supported \n");
|
|
return -1;
|
|
}
|
|
|
|
if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
|
|
printf("\nConnection Failed \n");
|
|
return -1;
|
|
}
|
|
|
|
printf("Sending %d MB of data...\n", TARGET_MB);
|
|
|
|
long long bytes_to_send = TARGET_MB * 1024 * 1024;
|
|
long long bytes_sent = 0;
|
|
|
|
while (bytes_sent < bytes_to_send) {
|
|
int to_send = (bytes_to_send - bytes_sent > BUFFER_SIZE) ? BUFFER_SIZE : (bytes_to_send - bytes_sent);
|
|
send(sock, buffer, to_send, 0);
|
|
bytes_sent += to_send;
|
|
}
|
|
|
|
printf("Data sent.\n");
|
|
close(sock);
|
|
|
|
return 0;
|
|
}
|