Viewing a single comment thread. View all comments

icydee t1_j1yvee6 wrote

Think of it like a big apartment block with a single letter delivery address. Each room in the apartment is identified by a number 0 to 65535 and any incoming letter is sent to that room.

Any incoming letters with address 80 go to apartment 80. Now apartment 80 may be unoccupied in which case the letter is ignored. However it is agreed that by convention apartment 80 is the home of the HTTP application, that knows how to read and process that letter, and send back a reply letter to the sender.

Other applications have their preferred room number, to make it easier to communicate with, simple email prefers room 25, file transfer is greedy and needs two rooms, 20 and 21. Etc.

These common applications prefer the ground floor rooms, 0 to 1023 so it usually means that they have to have special permission from the building supervisor to move in.

Of course there is nothing stopping applications taking other room numbers, you will sometimes find HTTP also in room 8080 but any number is possible from 1024 to 49151 and applications are free to move in to any room so long as it’s not already occupied. Terraria likes the view from room 7777 and tries to move in there (and because it’s users have difficulty remembering their room number otherwise!)

All the rooms on the top floors, 49152 to 65535 are available to be used by applications dynamically, think of them as Airbnb rooms, use them for a short while then move out and let someone else use them.

8

insultant_ t1_j1zyqgd wrote

Why can’t port numbers below 49152 act like “Airbnb for applications?” Conversely, why can’t port 49153 and above have, per your analogy, “long-term tenants.” Or can they?

Furthermore, what event on the server would be equivalent to “evicting” a program from its “apartment?”

1

DragonFireCK t1_j20a7hk wrote

>Why can’t port numbers below 49152 act like “Airbnb for applications?” Conversely, why can’t port 49153 and above have, per your analogy, “long-term tenants.” Or can they?

Convention - the same as why a hotel room generally won't have a long-term occupant and an apartment won't have a short-term renter. With that, its also likely somebody else may be using them for their intended purpose, thus causing random failures if an application tries to use them incorrectly.

Firewalls will also frequently block or allow specific ports by number, though they will normally only block incoming connections, not outgoing. This may cause a program using an unexpected port to get incorrectly blocked, requiring users to manually open those ports.

>Furthermore, what event on the server would be equivalent to “evicting” a program from its “apartment?”

Generally, the operating system will have a method of force disconnecting a socket, though such APIs are normally tightly restricted in usage. In most cases, they are restricted to usage by debugging tools.

2

interwebz_2021 t1_j210clo wrote

>socket

Just in case anyone's not seen the term 'socket' before: this is a logical address comprised of the IP address and port. So, for instance, if you have a web server listening on port 80 on your local loopback interface with IP address 127.0.0.1, you can connect to the webserver via the socket with address 127.0.0.1:80

3

bbqroast t1_j210p6p wrote

Applications that are waiting for anyone to mail them (i.e. server apps) need to "bind" a port and listen for traffic.

They generally do this on a specific port, this is so applications that want to talk to them can find them.

Applications that just want to start a chat with someone (i.e. client apps) can use a random one of the temporary ports as a return address for the duration of the correspondence.

If they use a port outside that range, then potentially they might prevent one of the applications that needs to listen to a specific port from starting (only one app can use a port at once). Likewise, if you decide to use a specific port in the temporary range, you run the risk it's randomly in use by someone else

2