Have you ever wondered how your computer plays a video you pick on the internet on your screen? It's like magic, right? Well, it's not exactly magic, but it's something super cool called "ports" that make all of this happen!
What are ports?
Ports are like little doors on your computer. Each door has a number, and behind each door is a specific treasure or piece of information. When your computer wants to share a picture with another device or computer, it puts that picture behind a door (port) and sends it on its way. The other computer knows which door to open to get the picture!
In this exciting journey through our blog, we're going to dive into the world of ports. We'll uncover the secrets of how computers use these doors to send and receive data. We'll also learn how these magical doors help the internet work smoothly, connecting devices and computers all around the world.
Before going to the magic doors let's understand how data can be shared with the help of hardware ports
Sharing data from the computer to the other device/computer through the hardware is called Physical I/O ports
What are physical ports?
The physical connectors on a computer or other device allow a cable to be plugged in. They are used to transfer data between the device and other devices, such as printers, mobile phones, and external hard drives.
Some examples of Physical I/O ports: USB, HDMI, Ethernet
But what about things that are far away, where we can't go and physically connect, or data that can't travel through the physical ports, like websites and such?
This is where the magic of ports comes into play, often referred to as "Logical Ports."
Logical I/O ports are special names given to specific software services or applications. These names help computers know where to send and receive the right information. Just like you'd remember a friend's phone number to call them, computers use these logical port names to talk to different services and share data. It's a bit like having a secret code that tells the computer where to send a message in the big world of the internet.
Just like physical ports have limited spots, logical ports also have a range, numbered from 0 to 65535.
But what do these numbers mean?
Let's make it easy to understand. Imagine you have a huge warehouse. Inside this warehouse, there are different rooms where things are stored. Each room has its number, starting from 0 and going up to 65535. In each room, there are special things that serve different purposes.
Now, here's the cool part. Some rooms are already taken, some are for others to use and own and some are used as per the demand.
Computers and servers work similarly. They have these special doors called "ports," just like the rooms in the warehouse. These ports are like magic doors that go from 0 to 65535. Each port has its job, just like each room in the warehouse has different things.
So, think of these port numbers as a way for computers to know which door to knock on to get the right service. It's like having a map for the digital world, showing where all the important places are.
The category of ports :
Well-Known Ports (0-1023): These ports are reserved and cannot be claimed by developers or applications. Both the client (your device) and the server (the website or service) are aware of these well-known port numbers, allowing data to flow smoothly without much introduction.
For instance, HTTP uses 80, while SSH uses 22, and so on.
Registered Ports (1024-49151): These ports are like empty rooms in the warehouse waiting to be assigned a purpose. Vendors and organizations can register their services to claim a room. While they might not be as famous as well-known services, they serve niche purposes. This area is often used for new or experimental services that are carving out their own space in the digital world.
For instance, Postgres uses 5432, while MySql uses 3306, and so on.
Dynamic Ports (49152-65535): Certain rooms within the warehouse are utilized based on demand and are subsequently vacated once their tasks are completed.
Indeed, comprehending the concept of magic doors (ports) isn't the sole ingredient for successfully accessing data from a computer or server. Just as it's crucial to navigate the paths leading to the doors, every warehouse possesses its distinct identity (analogous to an address), similarly, each computer or server holds its unique identity (IP address) which serves as the guiding route to the specific door (port).
Now it's time to understand this with a real-time instance.
Imagine a user sitting at one computer(user/client), eager to access a webpage.
They type the webpage address into their browser.
The webpage address gives back the webpage from another computer(warehouse/server).
Now this is how the client travels through the intermediary called the internet (in the case of physical port it is cables ).
Assume this is the webpage address of the user who tries to access "example.com"
But wait if we want to reach the door we need to know the address, but the client only knows their name. they don't have their exact address.
first, the client finds the address from the local registry if it can't able to find then it goes to the common registry called the DNS server
Think of DNS servers like phonebooks for the internet. They have lists of website names and their matching IP addresses.
This DNS server now gives the address associated with the name 123.456.789.123
Now that we've acquired the address and effectively reached the other computer (the warehouse), the client's next task is to pinpoint the specific room where the desired content is stored.
Consider our earlier scenario: the client aimed to access the content using "example.com" If we observe closely, the client aimed to access content located at door number 80, following the port principle. In this case, "HTTP" acts as the room name, and it falls under the category of well-known ports. This knowledge of the address and room number empowers the client's computer to retrieve the data (the website) through the internet from another computer.
the computer from which the user seeks to access the webpage plays the role of the client.
The other computer(warehouse) which gives back the data to the client is termed a server.
the client's inquiry for the webpage is termed a request, and the server's delivery of the content back to the client is known as a response.
Conclusion:
In the real world, it's not always the case that the well-known ports contain the precise content the client is seeking. More often, the content is exposed through registered ports. In the upcoming blogs, we'll delve deeper into how servers receive and process requests before providing responses. We'll explore the intricate lifecycle of this communication.
As we conclude this chapter, remember that the digital journey involves more than just magic doors (ports). It encompasses the intricacies of communication, request handling, and response delivery. So, stay tuned for our upcoming exploration, where we'll uncover the hidden mechanisms that bring the internet to life, one port at a time.