How do routers manage multiple data streams?

joshreesjones asked:

Routers manage data connections between the internet and computers or connections between computers on a LAN. It makes sense that when, for example, a computer requests music from Pandora, that packets containing music data from Pandora are routed from the internet connection to the computer that requested it.

What if two computers are requesting music from Pandora at the same time? How does the router manage the two incoming data streams? Does it complete one request and move on to the next, similar to a stack, or does it jump between requests, similar to threads, or does it do something totally different?

My answer:

It’s pretty easy:

A unique connection, or flow, is identified by four numbers:

  1. The source IP address.
  2. The source port.
  3. The destination IP address.
  4. The destination port.

Thus in the general case it’s trivial to disambiguate between your Pandora stream and your coworker’s.

Packets coming in to a router are generally processed in the order they’re received, unless the router is instructed to handle them differently (e.g. to provide traffic shaping/quality of service). But a full discussion of that is rather too broad for an answer here.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.