In computer networking, network is a group of interconnected devices (computers, servers, etc.) that are connected through various communication channels (wired or wireless). The main idea behind network is to allow resource sharing, data exchange, and communication among connected devices. Networks can vary in size, from small home networks to large networks like the Internet.
The devices within a network communicate with each other by following certain rules or protocols, known as network protocols. These protocols are standardized methods for exchanging data and ensuring reliable and efficient communication between devices.
Open Systems Interconnection (OSI) model is a framework for understanding how computer systems communicate over a network. The OSI model consists of seven layers, each of which represents a different aspect of networking.
Internet Protocol (IP) is a network layer protocol that allows data packets to be routed and addressed in order to pass through networks and reach their destination. So, when one machine wants to send data to another machine, it sends it in the form of IP packets.
An IP packet is the fundamental unit of data that is transmitted over the internet or any other network that uses the Internet Protocol (IP). It is a standardized format for transmitting data between devices on a network.
The IP packet has two main parts: IP header and data (payload).
The size of the packet includes the size of both IP header and data section. Other important information in the IP header includes: 1) Time-to-live (TTL) field, which determines the number of hops a packet can make before it's discarded 2) Protocol field, which specifies the protocol being used for the data section.
When a device sends a packet, it first determines the IP address of the destination device. The packet is then sent to the first hop on the network i.e. a router. The router examines the destination IP address in the header and determines the next hop on the network to which the packet should be forwarded. This process continues until the packet reaches its final destination. Note: Here routing algorithms are used to determine the best path for the packets to take through the network. We will cover various routing algorithms in a separate blog.
IP addresses are like digital addresses that identify and locate devices on a network. They are unique and assigned to each device or domain that connects to the Internet.
IP addresses are written as four numbers separated by periods, such as 192.168.1.1. These numbers represent the numerical value of the address. There are two main types of IP addresses: IPv4 and IPv6.
IPv4 was the first version of IP introduced in 1983. It uses a 32-bit address scheme i.e. it can accommodate a maximum of 4,294,967,296 unique IP addresses. Despite its limitations, IPv4 still carries a significant chunk of internet traffic today, around 94%. IPv4 also provides several benefits like encrypted data transmission and cost-effective data routing.
With the increasing demand for IP addresses, IPv6 was developed in the 1990s to overcome the limitations of IPv4. It uses 128-bit address space, capable of accommodating 3.4 x 10^38 unique IP addresses. It is also known as IPng (Internet Protocol next generation). Note: IPv6 offers improved routing, packet processing and security features compared to IP4. But IPv6 is not compatible with IPv4, and upgrading can present a challenge.
When sending large files, such as images or emails, a single IP packet may not be sufficient. In these cases, multiple packets are used to transmit the data. Unfortunately, this increases the risk of packets not reaching their destination, getting lost, or arriving in the wrong order. That's where the transport layer protocol comes into the picture.
The Transmission Control Protocol (TCP) is a transport layer protocol, which is built on top of the Internet Protocol (IP). It is often used in conjunction with the IP to provide a complete suite of communication protocols for transmitting data.
Here is how TCP works:
TCP is used by a wide range of applications. Here are some examples:
UDP is a connectionless transport layer protocol. Unlike TCP, UDP does not provide any reliability, flow control, or error recovery functions. As a result, UDP is useful in situations where reliability mechanisms of TCP are not necessary and faster transmission is desired. In other words, UDP is useful in applications where speed and low latency are more important than reliability, and where dropped packets can be tolerated without significant impact on the overall application performance.
Here is how UDP works:
There are some situations where UDP is preferred over TCP.
Hypertext Transfer Protocol (HTTP) is an application layer protocol used for communication in distributed, collaborative, and hypermedia information systems. It is built on top of Transmission Control Protocol (TCP) and provides a higher level of abstraction that allow developers to focus on their applications rather than the details of TCP and IP packets. Some common HTTP methods include PUT, GET, POST, and DELETE.
HTTP has several benefits that make it a popular choice for transmitting information over the web. It requires low memory and CPU usage due to its few concurrent connections. Additionally, it has the ability to report errors without closing connections, which can reduce network congestion. But HTTP is not equipped with encryption capabilities, so it may not be the most secure option for transmitting sensitive information.
Hypertext Transfer Protocol Secure (HTTPS) is a secured version of Hypertext Transfer Protocol (HTTP). Unlike HTTP, which transfers data in a plain text format, HTTPS transfers data in an encrypted format and protects it from interpretation or modification by hackers during the transfer of packets.
It is often used when sensitive information, such as passwords and financial transactions, is transmitted. But HTTPS may be slower than HTTP due to the overhead of the encryption and decryption process.
File Transfer Protocol (FTP) is used for transferring files between hosts, both local and remote. It runs on top of Transmission Control Protocol (TCP) and creates two TCP connections: control connection and data connection. Control connection is used to transfer control information, such as passwords and commands to retrieve and store files, while data connection is used to transfer the actual file. Both connections run in parallel during the entire file transfer process.
FTP has several advantages the ability to share large files and multiple directories at the same time, resume file sharing if it is interrupted, recover lost data and schedule file transfers. But FTP has some disadvantages as well. It lacks security, as data, usernames, and passwords are transferred in plain text, which makes them vulnerable to malicious actors. FTP also lacks encryption capabilities, which makes it non-compliant with industry standards.
Remote Procedure Call (RPC) is a protocol that allows a program on one device to request a service from a program on another device over a network, without the need to understand details of the network. It is used for interprocess communication in client-server based applications and is also known as a subroutine call or function call.
RPC works on a client-server model, where requesting program is the client and service providing program is the server. It uses either Transmission Control Protocol (TCP) or the User Datagram Protocol (UDP) to carry messages between communicating programs.
There are several advantages to using RPC. It can improve performance by omitting many protocol layers and minimize code rewriting or redevelopment efforts. However, RPC has not yet been proven to work effectively over wide-area networks and does not support other transport protocols besides TCP/IP.
Thanks to Chiranjeev and Navtosh for his contribution in creating the first version of this content. If you have any queries/doubts/feedback, please write us at contact@enjoyalgorithms.com. Enjoy learning, Enjoy system design, Enjoy algorithms!
Subscribe to get well designed content on data structure and algorithms, machine learning, system design, object orientd programming and math.