In this article post we will dive into the server terminologies and their understanding in layman terms.
1️⃣ IP Address
An IP address (Internet Protocol address) is a unique identifier assigned to devices connected to a network, enabling them to communicate with one another. There are two versions of IP addresses:
- IPv4: A 32-bit address represented as four decimal numbers separated by dots (e.g.,
192.168.1.1
). - IPv6: A 128-bit address represented as eight groups of four hexadecimal digits separated by colons (e.g.,
2001:0db8:85a3:0000:0000:8a2e:0370:7334
).
Types of IP Addresses:
- Private IP Addresses: Used within private networks (e.g., home or office LAN). Examples include:
192.168.x.x
10.x.x.x
172.16.x.x
to172.31.x.x
- Public IP Addresses: Used for devices on the internet. These are unique globally and assigned by ISPs.
- Static IP Address: Fixed and does not change.
- Dynamic IP Address: Assigned temporarily and may change over time, usually by a DHCP server.
2️⃣ Socket
A socket is a software endpoint that enables communication between two devices over a network. It acts as an interface for sending and receiving data, allowing programs to exchange information.
- A socket is an abstraction that represents one end of a communication link between two programs running on a network.
- It allows applications to send or receive data over the network using standard protocols.
Types of Sockets:
- Stream Sockets (TCP):
- Provide reliable, ordered, and error-checked delivery of data.
- Often used for applications requiring guaranteed data transfer, such as web servers and email.
- Datagram Sockets (UDP):
- Provide faster, connectionless communication but without guarantees.
- Suitable for real-time applications like video streaming and gaming.
- Raw Sockets:
- Allow direct access to lower-level network layers, often used for network diagnostics and custom protocols.
3️⃣ Port
A port is a virtual communication endpoint that allows computers and devices to identify and differentiate between multiple services or applications running on the same device. Ports work alongside IP addresses to direct data to the correct application or service.
How Ports Work:
- IP Address: Identifies the device on a network (like a street address).
- Port: Identifies the specific application or service on the device (like an apartment number).
For example, if a server hosts a website and an email service, the IP address identifies the server, and ports differentiate between the two services:
- Port 80: HTTP (Web Traffic)
- Port 25: SMTP (Email Sending)
Port Numbers:
Ports are represented by a 16-bit number, ranging from 0 to 65535. These are divided into three categories:
- Well-Known Ports (0–1023):
- Reserved for common protocols and services.
- Examples:
- 80: HTTP
- 443: HTTPS
- 22: SSH
- 25: SMTP
- Registered Ports (1024–49151):
- Assigned to specific applications or services by organizations.
- Examples:
- 3306: MySQL
- 5432: PostgreSQL
- Dynamic/Private Ports (49152–65535):
- Used for temporary or custom purposes, often assigned dynamically by the operating system.
- Commonly used for outbound connections.
Why Are Ports Important?
- Multiplexing: A single IP address can host multiple services, with ports allowing the OS to route data to the correct service.
- Security: Ports can be restricted or monitored to enhance security.
- Communication: Specific applications listen on specific ports to establish communication.
How Ports Are Used:
- Client-Side Ports (Ephemeral Ports):
- Temporarily assigned to the client device for communication.
- Used in the dynamic/private range (49152–65535).
- Server-Side Ports:
- Applications or services listen on specific well-known or registered ports to receive incoming requests.
Port Security:
- Firewalls: Can block or allow traffic to specific ports.
- Port Scanning: Tools like
nmap
are used to identify open ports, which can help in troubleshooting or detecting vulnerabilities. - Port Forwarding: Redirects traffic from one port to another, often used in routers.
Examples:
- Accessing a Website:
- The browser connects to the server's IP on port 80 (HTTP) or 443 (HTTPS).
- SSH Connection
- A terminal connects to a server's IP on port 22.
- Running Multiple Services:
- A server can host a website (port 80), a database (port 3306), and an email service (port 25) simultaneously.
Real Life Analogy:
A port in networking can be understood through a simple real-life analogy of a building with many apartments:
Building and Apartments Analogy:
- Building (IP Address):
- Imagine a building that has a unique street address. This represents the IP address, which identifies a specific device on the network.
- Apartments (Ports):
- Inside the building, there are multiple apartments, each with its own unique number. These are the ports, which identify specific services or applications on the device.
- Visitors (Data Packets):
- When someone (a data packet) wants to deliver something (information), they not only need the building address (IP) but also the apartment number (port) to know exactly where to deliver it.
Example in Action:
- Web Browsing:
- You visit
https://example.com
. - The IP address directs the request to the building (server), and the port number (443 for HTTPS) ensures it reaches the correct apartment (web service).
- You visit
- Mail Delivery:
- A mail carrier (your email client) needs to deliver mail to an email server.
- The IP address is like the building address, and the port (e.g., 25 for SMTP) ensures the mail reaches the specific email-handling service (apartment).
4️⃣ Protocol
A protocol is a set of rules that define how devices communicate over a network.
5️⃣ Client
A client is a device or program that initiates a connection to a server to request services.
Example: Your web browser is a client when accessing a website.
6️⃣ Server
A server is a device or program that listens for and responds to client requests.
Example: A web server hosting a website.
7️⃣ Binding
In socket programming, binding associates a socket with a specific IP address and port so that it can listen for incoming connections.
8️⃣ Listening
When a server socket is in a listening state, it waits for incoming connection requests from clients.
9️⃣ Accepting
A server accepts a connection when a client requests to connect, creating a new socket to handle the communication.
1️⃣0️⃣ Sending and Receiving
- Send: The action of transmitting data through a socket.
- Receive: The action of reading data from a socket.
1️⃣1️⃣ Packet
A packet is a small unit of data sent over a network. It includes:
- Header: Contains metadata (source/destination IPs, ports, etc.).
- Payload: The actual data being transmitted.
1️⃣2️⃣ DNS (Domain Name System)
DNS translates human-readable domain names (like example.com
) into IP addresses.
1️⃣3️⃣ Firewall
A security system that monitors and controls incoming and outgoing network traffic based on rules, often blocking or allowing traffic to specific ports.
1️⃣4️⃣ Socket Descriptor
A socket descriptor is a unique identifier (usually an integer) assigned to a socket when it’s created.
1️⃣5️⃣ Handshake
A handshake is the process of establishing a connection.
Example: TCP uses a three-way handshake to initiate a reliable connection.
1️⃣6️⃣ Datagram
A datagram is a self-contained packet of data sent over UDP. Unlike a TCP stream, it doesn’t guarantee delivery or order.
https://medium.com/@ahnafzamil/networking-101-what-are-sockets-7e2d274e153