2
1
I'm wondering whether TCP client can use the same port to connec to different remote TCP servers or not?
In network-programming, there are two functions: sendto
and send
. When WE use send
we don't need to specify the destination. This seems to mean that a connected tcp socket can only be related to one (src ip, src port, dst ip, dst port) 4-tuple.
can I do something like:
sockfd=socket(AF_INET,SOCK_STREAM,0);
bzero(&cliaddr,sizeof(cliaddr));
cliaddr.sin_family = AF_INET;
cliaddr.sin_addr.s_addr=inet_addr(local_ip);
cliaddr.sin_port=htons(32000);
bind(listenfd,(struct sockaddr *)&cliaddr,sizeof(cliaddr));
connect(sockfd, (struct sockaddr *)&servaddr1, sizeof(servaddr1));
connect(sockfd, (struct sockaddr *)&servaddr2, sizeof(servaddr2));
sendto(sockfd, buf, len, 0, (struct sockaddr *)&servaddr1, socklen);
sendto(sockfd, buf, len, 0, (struct sockaddr *)&servaddr2, socklen);
for example, is it possible http proxy may run out of ports and have to reuse ports?
1
"Can TCP clients use the same port" -- do you mean src or dst port? Perhaps http://en.wikipedia.org/wiki/Port_(computer_networking)#Technical_details will give you some hints. Btw. this is not a programming question, is it?
– mpy – 2013-05-27T14:40:03.323I mean the TCP client port – misteryes – 2013-05-27T18:35:38.703