Understanding Network Ports
Not to be confused with the physical ports on the computer where devices (mouse, speakers, etc.) are plugged in.
A computer is represented by its IP address on the network which is like a phone number of the computer. Every computer on a network has an IP address that helps another computer talk to it. So, when we go to my website https://upretip.com.np we are calling a computer on the internet that has a number (like 104.248.63.248). Converting from upretip.com.np to something like 104.248.63.248 is done by something called Domain Name System (DNS) Server (a topic for a different day). While this computer could do a variety of tasks all at the same time, all other activities, except for access to this website, are unaccessible from other computers (unless you are a really good hacker). The ports on these computer control what can be accessed from the network. Ports on a computer are like extensions on an office phone[1]. Not all ports need to be exposed to external connection the same way not all extension can be dialed from outside the office. Some departments or personnel can be called using their extension from an external telephone; and likewise, specific ports can be directly called upon for specific services. Not all ports are assigned; there are many unused ports.
I usually check whether a port is open using a website like https://ipfingerprints.com or more generally using a command line tool called netcat
nc -zv -w5 google.com 80
In fact there are more than 65,000 ports in every computer. 2^16 to be precise. Of these, the first 2^10 (i.e. ports 0-1023) are special ports that are reserved for use by special programs. For example, some of the important ports I come across (not comprehensive) are Ports 20 and 21 for FTP, port 22 for SFTP and SSH, ports 80 and 443 for HTTP/s, etc. Then there are special (but not so reserved) ports that become common knowledge. In my experience, Postgres database communicate on port 5432, Oracle database on 1521, etc. A complete table of ports and their uses is available on this Wikipedia article.
So, next time we build a flask app and enter http://localhost:5000 to test out the app, we have a better understanding. This combination of internet protocol, IP address, and port is called internet socket. Here “localhost” will resolve to 127.0.0.1 which is pointing back to our own computer and the port is the port we asked this test server to run on. Once this app is ready and we deploy it on a remote server, we will most likely configure it with web server and reverse-proxy that will listen on port 80 and 443. We will calibrate our web app in a way that the default port it will be listening will be on those port the same way the office telephone by default will connect to the reception or operator. I will try to update this as I learn more on this topic.