Networking – How does a server distinguish between multiple requests from same ip address and port

ipnetworkingportwebserver

When multiple requests are sent to a server to the same poft 80 or whatever and from the same ip address, say, from a computer behind NAT or from the same computer but different browsers or by different applications on the same computer, how does a server distinguish between them and is able to reply?

Best Answer

The client will use a different source port for every TCP session (request), so there are 4 parameters associated with each connection:

  • Source IP
  • Source port
  • Destination IP
  • Destination port

As you can see in netstat output, for example my web browser has several connections to the StackExchange network, on different source ports (40092, 40094, 40096):

tcp        0      0 192.168.x.42:40092     151.101.129.69:80       TIME_WAIT  
tcp        0      0 192.168.x.42:40096     151.101.129.69:80       TIME_WAIT  
tcp        0      0 192.168.x.42:40094     151.101.129.69:80       TIME_WAIT  

The server will be able to differentiate the connections based on the source port used by the client.

Related Question