How does a server program distinguish between clients

2

Why does a web server listening on port 80 not get confused with many packets coming from different hosts. Why does it not confuse packets coming from the same host when different browsers access the server simultaneously?

Holy Sheet

Posted 2012-10-01T16:19:32.047

Reputation: 481

Answers

4

Because the packets have a source IP-address and a Source port - together these uniquely identify each connection

When your two browsers on one PC want to fetch a URL they ask the operating system (OS) to set up a connection, The OS chooses a random source-port address for each connection.

RedGrittyBrick

Posted 2012-10-01T16:19:32.047

Reputation: 70 632

...known as sockets (http://en.wikipedia.org/wiki/Network_socket).

– user142485 – 2012-10-01T16:53:14.383

so source port and port are different things here. Like httpserver runs on port 80. but it can still receive things on different source ports. – Muhammad Umer – 2013-03-05T04:26:57.287

@Muhammad: A port can act as either a source port (sending packets) or a destination-port (receiving them). A TCP connection has source-ports and destination-ports. A server receives requests on destination ports. Each service on the server binds to and listens on one or more pre-specified destination-ports. Each destination-port that is in use is allocated to a single specific service. When the server replies (through an established TCP connection) the port roles are reversed. – RedGrittyBrick – 2013-03-05T09:41:45.133

@RedGrittyBrick I think the Source port in IP packet is the port assigned by NAT Router, not the OS – onmyway133 – 2013-03-21T04:22:10.330

@entropy: It depends where the packet is in it's journey, and whether any routers use NAT (which is common nowadays at edge routers but not required if you have sufficient IP-addresses allocated to you). You could also consider the effects of proxies etc but these are details that don't clarify the main point of the question. – RedGrittyBrick – 2013-03-21T09:09:31.733