I know that TCP/UDP socket identified by 5-tuple, (protocol, src IP, src PORT, dst IP, dst PORT).
I thought that, theoretically, two TCP client socket on same src IP:src PORT can exist if dst IP:dst PORT differ.
So, out of curiosity, I did a simple test:
- run web servers on 127.0.0.1:8000 and 127.0.0:8001
- run client socket program that requests to server 8000.
- run same client program on same src IP:src port, but requests to server 8001.
Server return message every second for 10 seconds for keeping connection.
Both client are bind()
ed manually, set SO_REUSEADDR
.
Because it cannot be decided which process to send each packet to, I expected the output of the returned message to be messed up in each client process. But the message was sent correctly to each of the clients who made the request.
I can't understand how it worked. What am I missing?
CodePudding user response:
You actually answered your own question:
I know that TCP/UDP socket identified by 5-tuple, (protocol, src IP, src PORT, dst IP, dst PORT)
The first client's 5-tuple differs from the second client's 5-tuple because the "dst PORT" is different.