单线程
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/time.h>
#define BUFFER_SIZE (1024 * 1024) // 1MB buffer
#define TEST_DURATION 10 // 假定客户端也会持续发送数据同样的时长
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <server_port>\n", argv[0]);
return 1;
}
int server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (server_sockfd < 0) {
perror("socket creation failed");
return 1;
}
struct sockaddr_in server_addr;
memset(&