I'm aware of NAT table. I just want to know what happens if two clients in a private local area network want to download exactly the same resource on the same port? In other words , When a packet comes from the server, how can the router decide which client is supposed to get this packet?
If I'm not wrong, the incoming packet from the server has destination IP address of the router which is public and is the same for both, and also the destination's port number which happens to be the same as well in this case.
Is there any mechanism in router or server to detect this ? or is this behavior even possible at the first place?
I've searched questions like this, which makes sense that the error raises because the port is busy but I'm asking about two separate systems.
Update : From comments I realized that I wasn't clear enough so let me say it again with an example:
I just care about devices' "source" port. Assume I have two laptops (
192.168.2.11), both of them are downloading same file from the same server somewhere in the internet. Each of them has an operating system which generates a random port so the source IP and source port would be something like:
192.168.2.11:7132. I thought that in NAT, router will set it's (public)IP address along with the ports from laptops so if the public IP address of the home router is
184.108.40.206, these two packages will get these source IP and source port respectively :
Now when the response gets back, router can figure out which packet is for which laptop from the port numbers right ? so far so good. But what happens if accidentally or intentionally two laptops generate exactly the same source port? for example :
192.168.2.11:6000. Now router will set it's public IP address as the source IP address just as before, but now if it tries to use those port numbers, those packages will have exactly the same source IP and source port number, like :
This is where I got confused that when the response comes back, how router can decide which packet is for which laptop ?
After @mfinni's answer, I noticed that this is not how PAT works! The NAT device (here router) will assign unique ports to each individual laptop(private IP address), then the packets sent out with these unique ports(for example
7778). So when response gets back, it's clear that which packet is for which laptop from the ports, then router will convert these
220.127.116.11:7778 to -->