r/eli5_programming • • Apr 28 '22

Services - how do they work

Help me fill in the blanks...

I have a client and make a request -> [ something happens ] -> service code calling a coded function that's available on some machines

I get there are many styles of services, so just a common pattern would be useful

Can someone help me break down

  1. How a router/dispatcher works
  2. How a request gets routed to the right function
  3. What's it mean when someone says a service is running (what is running/listening mean)
  4. something else if the above are bad questions
3 Upvotes

5 comments sorted by

View all comments

Show parent comment

2

u/Snoo-471 Apr 29 '22

Sure, headers are bits of information that are added in front of the data that you want to send to the other computer. They include a transport header that is either TCP or UDP, but they both use the idea of port numbers to indicate which process should be receiving the data at the destination computer. There is an IP header that is put in front of the transport header that has the source and destination IP addresses along with some other information, and then in front of that header there is most commonly the ethernet header that contains the source and destination MAC addresses.

You can view these headers by downloading Wireshark and running it on your own computer, or if you want just find an introductory video on it on YouTube. It will show you the actual headers and the data that is flowing across your wires, but broken down into hearts. These headers are all put on before the data is sent out of the computer's ethernet or wireless interface.

The best way to describe each of their function I think is the analogy of sending a letter to someone...if people even still do that anymore lol. You have the thing you want the other person to read, that's the data. You know who should read it at the other house, that is the port number.

You know where they are in the world, that's their street address, state, country, etc and is the same idea as the IP address. Then the path that it takes from your house to the mailbox, the mailbox to the mailbag of the letter carrier, then the letter carrier giving it to the facility, then it going on an airplane to the next facility...those are all things that are basically the idea of MAC addresses, get the letter not to the ultimate destination, but to get it to the next closest place to the destination.

But that's all the networking stuff and isn't really what you asked about, in the example above not having the port number is like sending a letter to a house address (the IP address) but not saying who at the house is supposed to open it. Servers will use "well-known" port numbers for services that are commonly used. Port 80 is unencrypted web pages, port 443 is commonly used for encrypted web pages.

You don't actually have to use 80 or 443 for a webpage, that's just the default that a web browser will ask for when you get an IP address and put it in the web browser (which is usually the DNS name, but that is really just a lookup for an IP address). If you put a colon after the name you can tell it to use a different port number, but it doesn't make sense to have people guess which port number you're using if you want them to find your webpage, so most people stick with the default or tell the client to redirect to a different port number after the first communication.

EDIT I should also say that basically every device between you and the destination computer just checks the headers that your computer put on before it sent the packet to determine where to send it to next.