13
$\begingroup$

What would be a good way to describe ports? I learned about it using this analogy, but it seems pretty inadequate to me:

IP addresses are like street addresses of apartment buildings, and ports are like the apartments therein.

IP addresses are not segmented as a street address is, and second, apartments don't seem at all analogous to ports in terms of behavior.

$\endgroup$
  • 10
    $\begingroup$ I don't know how many times I've seen the IP address compared to a phone number, with the DNS being the phone book. To add ports to that, just add extensions to the phone number. Extensions that are standardized so you always know which extension to connect to for some department. The web department is normally extension 80, the email department uses extension 25. If you have an encrypted phone then you used different extensions. $\endgroup$ – Gypsy Spellweaver Jul 2 '17 at 3:13
  • 6
    $\begingroup$ Analogies are like shoes ... they do not always fit perfectly. $\endgroup$ – Hagen von Eitzen Jul 2 '17 at 10:43
  • $\begingroup$ The apartment street address vs. apartment number is the analogy I use, and it seems to work. Anything could work though - buildings and room numbers, classrooms and seats, pbx and extensions (this may add confusion) - as long as it references one destination with service dependent on who is contacted at that destination $\endgroup$ – ivanivan Jul 2 '17 at 19:41
  • $\begingroup$ Phone numbers also have the name<->number mapping in form of telephone books (which may be a thing of the past though). $\endgroup$ – Thorbjørn Ravn Andersen Jul 7 '17 at 18:13
  • $\begingroup$ why use an analogy? I would maybe use an analogy to explain it to someone not interested in computers to give them a quick idea of what it's for, but if you're actually teaching someone about IP addresses and ports, I don't see how an analogy helps, just tell them how it works. An analogy might actually be counter-productive, in fact. $\endgroup$ – Dave Cousineau Jul 8 '17 at 3:08
8
$\begingroup$

I don't think the address metaphor is that off-the-mark -- real addresses are more segmented then IP addresses, true, but I don't know if that's really that much of a conceptual barrier.

Regarding ports, I would tweak your metaphor slightly -- a port is more like an apartment number, rather then the apartment itself. That is, the port just serves as an additional piece of information that's a part of your overall address, and can be used to route the mail to the appropriate apartment resident once your mail arrives.

(I guess to extend the metaphor, the people who live in the apartments are programs, and whoever sorts the mail at the apartment is like the operating system.)

What might also help is to explain that at the end of the day, a port is literally just a 16 bit int, nothing more, and that it's up to the receiving computer to do something reasonable with that number. If you emphasize that a port is just a number, it might make it a little easier for your students to independently derive what exactly you can and can't do with ports. After all, there are only so many things you can do with a single piece of metadata.

An alternative/complementary approach might be to focus less on metaphors and instead focus on motivating why we'd need ports in the first place. I'd personally start from the top down, and explain things like this:

  1. Start by explaining how IP addresses are used to route packets.
  2. Explain that once a computer finally receives a packet, we're still not done: the operating system need to figure out which currently-running program to give it to, if at all.

    This might also be a good moment to ask your students to discuss and try coming up with a solution themselves -- hopefully, most of them will independently realize they need to include metadata of some kind. You can turn this into a mini-design lesson: an ideal solution should be simple, minimizes packet size, is future-proof, flexible, doesn't break the transport layer abstraction...

  3. Tell them about ports, and explain that was the solution people ended up coming up with.

The hope is that focusing more on motivation will allow your students to acquire a reasonable conceptual model of how network protocols tend to work, even if they forget the exact details.

I think this approach also does a better job of answering the implicit "why?" question people have when learning new things. (Why ports? Why IP addresses? Why TCP? Why abstract things like this? Why is everything so complicated? etc.) Basically, confront it head-on by presenting things in a problem/motivation -> solution approach.

Caveat: this approach might just be a reflection of how I personally like learning things, so YMMV.

$\endgroup$
  • $\begingroup$ Concurring: port is the apartment number, not the apartment. The apartment dweller has to do something with the delivered mail, akin to the program listening at that port. My success with the apartment building:number::IP:port analogy increased when I started showing pictures of a bank of mailboxes: sep.yimg.com/ay/yhst-14044557065217/… $\endgroup$ – Bennett Brown Jul 2 '17 at 4:17
  • $\begingroup$ Why can we ping only houses, not appartments? In other words, a good metaphor would need good counterparts for TCP vs. UDP vs. IP. To begin with, there is in principle no relation between UDP port x and TCP port x (even if, e.g., DNS uses both UDP port 53 and TCP 53); even the fact that their number ranges are the same is not a principal necessity. My point is: Why try to use a metaphor at all to cover every aspect and detail, when pairs of numbers are a simple concept? $\endgroup$ – Hagen von Eitzen Jul 2 '17 at 10:51
8
$\begingroup$

I used seats in the room.

The classroom has an address. So, if someone wanted to come and talk to one of the students they would come down the hall and into my room.

But, that only gets them to the room (server). They need to talk to a specific person, so they go to seat 17 so they can talk to Bob.

So Bob's socket is room.123:17.

I tried once to continue and the floor became cable runs, each hallway was a subnet, the corners were routers, and the school map was DNS. That pushed it a little too far :)

Did find though that most kids had at least a passing understanding of ports. Most of them had opened ports on their home routers to play games over the internet.

$\endgroup$
  • $\begingroup$ Seats! Love it. The person in the seat is like the program registered with the OS to listen at that port. The analogy gets at the idea that programs at a port may or may not be the port's usual ilstener (students sit in the wrong seat), might not be running (absent student), and that programs might have assumptions they make about incoming packets. If a love note for Barb at 121:2 is sent to Alice at 121:1, who knows what Alice will do with it? Ignore it? Return receipt reporting incorrect delivery? Respond in a way that noone who knows Alice would have expected? $\endgroup$ – Bennett Brown Jul 2 '17 at 4:13
  • $\begingroup$ @BennettBrown That's even better. Bob and Sue switched seats because there's a substitute and now Bob doesn't get his message. $\endgroup$ – Ryan Nutt Jul 2 '17 at 14:33
3
$\begingroup$

You can consider an IP number to be analogous to a business's telephone number (reaching the main switchboard), and the port number to be the telephone extension number for one person.

This probably works better when there is no direct-dial to a specific person, and the main number is handled by an automated system.

$\endgroup$
  • 1
    $\begingroup$ That's a nice point. Welcome to Computer Science Educators - I hope we hear more from you in the future! $\endgroup$ – Ben I. Jul 2 '17 at 13:32
  • $\begingroup$ I've just noticed @Gypsy-Spellweaver 's comment to the original question, and realised that my answer is much the same. $\endgroup$ – CSM Jul 2 '17 at 13:45
2
$\begingroup$

I'd put a slight tweak on your analogy and go digital: email.

In email, your email address is your IP address. It comes in multiple parts, similar to IP blocks. There are many addresses under one domain, there are many domains under 1 TLD.

When a message is sent to an email address, it gets sent something pretended to the title, for example "Re" and "Fwd". That's similar to the port. They're all going to the same place, but it indicates something about the email that the computer can use to help process it.

$\endgroup$
2
$\begingroup$

As a former student I'd like to confess that for me these attempted analogies about the ports just made a simple thing sound mysterious and in retrospect had absolutely zero insight whatsoever.

What about saying instead that TCP/IP is just a program running on your computer like everything else and ports are just an integer in its configuration. That'd be a start.

$\endgroup$
  • $\begingroup$ Might work. Might fail. Depends on how much experience the students have. $\endgroup$ – ItamarG3 Jul 3 '17 at 12:24
1
$\begingroup$

How about IP addresses being countries and ports being sea ports?

In the UK it works well because there are so many different sea ports that students recognise from looking at an online map of the British Isles.

You can extend the metaphor by talking about firewalls blocking off access to ports (e.g. sea blockades during WWII) or increasing security by removing external access (landlocked countries don't need to worry about sea invasion).

The main advantage over an address / flat number analogy is that you can extend it by talking about different types of ports (e.g. airports) for different protocols (e.g. UDP / TCP) with various implications for speed / reliability.

No analogy is perfect though - students who want to understand it fully should have experience using or hosting different services on the same server.

$\endgroup$
  • 1
    $\begingroup$ This seems confusing. If a sea port like Liverpool is analogous to anything in networking I would expect it to be an interface, rather than a port. $\endgroup$ – bdsl Jul 2 '17 at 15:43
  • 1
    $\begingroup$ I could see this going badly in parts of the US, where some students may be only dimly aware that there are such things as oceans (or other countries) $\endgroup$ – David Z Jul 3 '17 at 11:36
1
$\begingroup$

Using physical addresses is misleading - it would be clearer to use an email address, or a phone number.

If people still had POTS (telephone) in the house, you have segmented (area code) dynamic addresses, and 'mum, dad, youngest child etc.' which could represent ports - which are ways of reaching the same type of person in each house.

With this analogy, you can explain that people's phone number sometimes changes (but doesn't have to, even if they move location), and there are many different ways of addressing a set of people who might be in a house. Depending on who is at home, a different person might actually handle any specific call.

When someone places an outgoing call, you'd see which house the call was coming from, but not who (until they identify themselves).

$\endgroup$
  • $\begingroup$ I don't understand. What are POTS? I mean, other than stovetop items. $\endgroup$ – Ben I. Jul 3 '17 at 15:14
  • $\begingroup$ Is it clear enough with that edit? $\endgroup$ – Sean Houlihane Jul 3 '17 at 15:16
  • $\begingroup$ Yes, thank you :) I grew up with one (still have one, actually), but never knew it was called that. $\endgroup$ – Ben I. Jul 3 '17 at 15:18
1
$\begingroup$

Our department is small enough and close-knit enough that most of my students have seen the CS mail room across from the CS main office. A mail room that has a wall of slots, one for each faculty and staff in the department. I tweak the address metaphor and talk about how the mail slot is analogous to a port. Address (IP) gets the letter (packet) to the right building (computer), while the name on the address gets the letter (packet) to the right person (port/service).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.