To be able to open more than 65536 TCP socket connections from your client computer, you really need to use more IP addresses.
Then, for each TCP socket connection, you must tell the kernel which IP address and which ephemeral port to use.
, TCP , , TCP IP-, , .
MigratoryData Benchmark Tools Java, , TCP- . , ++.
, TCP- 192.168.1.1:8800 , 192.168.1.10 IP- , IP- 192.168.1.10 - , 12345 - IP- 192.168.1.1 8800, - :
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include<sys/socket.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
int n, sockfd;
char buffer[1024];
struct sockaddr_in localaddr, remoteaddr;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
localaddr.sin_family = AF_INET;
localaddr.sin_addr.s_addr = inet_addr("192.168.1.10");
localaddr.sin_port = htons(12345);
bind(sockfd, (struct sockaddr *) &localaddr, sizeof(localaddr));
remoteaddr.sin_family = AF_INET;
remoteaddr.sin_addr.s_addr = inet_addr("192.168.1.1");
remoteaddr.sin_port = htons(80);
connect(sockfd, (struct sockaddr *) &remoteaddr, sizeof(remoteaddr));
n = read(sockfd, buffer, 512);
close(sockfd);
return 0;
}
source
share