Decoding Computer Network Ports: Your Gateway to Digital Conversations

Decoding Computer Network Ports: Your Gateway to Digital Conversations

What are Computer Network ports ? How are the assigned ? Are they required ?

I will try to answer all of these question in the simple way possible way. But before that we have to understand What a Computer Process is ?

What the hell is PROCESS?


A process, in the simplest terms, is a running app (or program) [Source: Microsoft https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process?view=net-8.0]

Suppose you have created a program irrespective of programming language (C/JS/Python/Java...). When you run the program (or app), the program executes as per the code written. Execution of program, require multiple things like:

Basic components of a process

- Code (Written in your fav programming language )

- Data / Files (User or File inputs ??)

- CPU (Thinking ability ??)

- Registers (Temporary memory for execution)

- Thread (The Executor ??)

- Stack (Maintains function calls & variables )


Whenever you run code, a process is created which is executed. A computer can run many processes, depending upon the hardware you have RAM & CPU, there can be multiple factors, but for now these are two requirements for how many processes can be spawned up. If you run the program multiple times at the same time instant, multiple processes of same code (program) are executed. Such practices are used in daily practices for example in Web Application Server. Operating System (Windows/Linux) binds a unique identifier called Process Identifier (PID) with each process to manage the resources.

For Windows you can check PID of your applications through a tool called Process Hacker 2 (mostly used for Digital Forensics) as

Seeing running processes with their PID in Process Hacker 2 tool

As shown images, Brave browser (application) has a Process ID (1296), VS code has 15444 PID. Each PID or Process requires above mentioned things. More on process on some another article ????.

Many of the processes require data exchange for which they might connect to other Computers/Servers etc.

Let's understand which hardware can help here.

- CPU ?? It's require to process or making computations

- RAM ?? It's for memory for variables

- NIC ?? Yes, Network Interface Card (NIC) , It is responsible for connecting your computer processes to network.

Consider an example, you are running following programs on your computer:

- Surfing internet (or watching funny cat videos ??) Chrome browser

- Listening to songs using spotify

- Chatting with friends through Whatsapp web

- And many more programs ...

All of these programs are exchaging data through the internet. As the data is travelling in binary 00110... ??, it is hard to understand which binary data belongs to which process. It might be possible to interpret wrong by the process, or the program crashes. What if there exists a identifier like PID to tell which data is transfered to (or by) which process. That's is the "Network Port number" ??.

A Computer has 65536 ports available from 0 to 65535. Each TCP and UDP have 65536 ports

  • Well-known port (0-1023)
  • Registered port (1024-49151),
  • Dynamic port is three types of port number space. (49152-65535).

NIC-CPU communication

OS assigns the PORT, but NIC is adding a layer to the data packet, while communication is happening. OS can assign port based on following things

  • First come first served: whatever port is available is assigned to the process
  • Random assigning: Randomly assigning the PORT
  • Reserved Port: Some system application have already defined reserved ports like SSH/HTTP/Telnet etc.

As you can see Brave browser is running on process 20848 (with multiple tabs) each assigned a local port as 55719, 56301, 56300 and many more.

Network PORT assigned to Brave browser application processes

I have created a main.py file which has two modes

  1. Do some process which does not require network connection
  2. Do some process which require network connection

Before running you can see no python process is listed in resource monitor

Processes are ordered alphabetically

Do some process which does not require network connection

Python process is spawned and CPU assigns a PID 17816 as per below image

Python Process without network requirements with 17816 PID

and No network PORT is assigned as per below image

In network panel, no python process is shown, which is expected

Do some process which require network connection

A new Python process with network requirements is spawned and CPU assigns a PID 7652 as per below image

Python Process with network requirements with 7652 PID

and this process is assigned a PORT 49772 (local PORT) as per below image

Process 7652 which require network communication, has been assigned a local port 49772

The other machine (also called Remote Machine) to which this program is exchanging the data, also require a PORT (as that is also exchanging the data over the wire), and PORT assigned to that machine is 65432.

This means that two programs are communicating over the internet and we should know the PORT number assigned to remote machine.

If we don't know it in advance while developing the client side program, there might be two scenarios possible

- either we won't be able to connect

- we will connect to wrong process of remote machine

Summing up...



Hence, PORTs are very essential to identify the process on the network. That's why many computer scientists when they developed their own protocols or programs like HTTP/SSH/FTP/Telnet etc, they have defined the PORT implicitly.

Common registered ports


I hope you find this article helpful.

Apologies for any mistake, and open to any suggestions


Peace Out ??♂?


Dharmik Thakkar

Flutter | Android | iOS

9 个月

#cfbr

要查看或添加评论,请登录

Mohitkumar Talreja的更多文章

  • Tar Compression: tarfile library in python

    Tar Compression: tarfile library in python

    Tar stands for Tape Archive is an archive file [record file] which is created by making group of some files. In the…

  • Understanding API Endpoints: Identifying which Magic Spell to Use ??♂?

    Understanding API Endpoints: Identifying which Magic Spell to Use ??♂?

    Hello everyone, hope you are doing well in this hot summer. I was trying a Third-Party Integration with my system…

    2 条评论
  • Templates searching in Django

    Templates searching in Django

    Hello Wizards, welcome to Django witchcraft ??, in this article We will see how does template searching works in Django…

  • Permissions: MAGICAL abilities to do THINGs ??

    Permissions: MAGICAL abilities to do THINGs ??

    Another BLOG on Authentication VS Authorization ??. Well no, in this blog I try to explain to you the Authorization and…

  • Django Extensions (cherry on the top)

    Django Extensions (cherry on the top)

    Hello Guys, Namaste! My name is Mohit, and I will discuss a library that enhances the Django App development process…

    2 条评论

社区洞察

其他会员也浏览了