0

When a socket is created between a client and host, it includes the IP address, protocol used and port number of both.

Suppose I have socket A (10.0.0.1, TCP, 50000) and (10.0.0.2, TCP, 50000) each connecting to (11.11.11.11, TCP, 80) (a web server).

Will there be a conflict at the web server since both sockets are using the same port?

1
  • Two TCP connections differ if one of the 4-tuple (source IP and port, destination IP and port) differs. So the scenario you describe is not a problem. If this would have been a problem it would be a nightmare since then all systems on the network/internet would somehow need to synchronize with each other in order to not use the same source port when accessing the same server. Commented Nov 1, 2023 at 20:03

2 Answers 2

2

No. The connection is identified by a 5-tuple that includes the source IP

Therefore, the server sees 2 different, distinguishable connections.

0
-2

While Steffen Ulrich's answer is valid, it's not quite what happens.

Your web server at 11.11.11.11:80 is only listening for one connection. When 10.0.0.1:50000 connects to it, it immediately assigns a new port for it, say 49001, and tells 10.0.0.1 that it is now talking to 11.11.11.11:49001 and goes back to listening for connections on port 80.

Now when 10.0.0.2:50000 connects, it is immediately told that it's now talking to 11.11.11.11:49007, and the web server goes back watching for people who want to connect to port 80.

So ports are different, and there is no conflict.

7
  • This isn't true for anything TCP-based. (Or even most things UDP-based, except perhaps TFTP.) It was how connection establishment in ARPANET NCP worked, but they moved away from that mechanism some 50 years ago. Commented Nov 1, 2023 at 21:25
  • Funny, I'm still being told to code servers that way. The Linux Programming API explicitly says that when a new thread is launched for a connection that has been made, it's assigned a new port... well, documentation, even recently released documentation, may still be behind the times I guess.
    – tsc_chazz
    Commented Nov 1, 2023 at 21:31
  • Can you cite sources for that? (I can cite Wireshark captures showing that this doesn't happen...) Commented Nov 1, 2023 at 21:33
  • Alas, no. Seems I misremembered something I saw in The Linux Programming Interface (Kerrisk 2010), probably conflated it with ancient historical documents from somewhere else. Ah, well...
    – tsc_chazz
    Commented Nov 1, 2023 at 21:48
  • 1
    Are you sure it didn't say a new server thread (for a new connection) gets a new PID=process-id? That is a property of Linux that differs from other Unixes and can matter to programming. Commented Nov 2, 2023 at 2:01

Not the answer you're looking for? Browse other questions tagged .