Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Basics of Computer Networking

Download as pdf or txt
Download as pdf or txt
You are on page 1of 110

Basics of Computer Networking

Last Updated : 29 Oct, 2024


Computer networking is very important in modern technology, enabling the
interconnected systems that power the Internet, business communications, and
everyday digital interactions. Understanding the fundamentals of computer
networking is essential for anyone involved in technology, from enthusiasts to
professionals. This article will explore the basics of computer networking,
including network types, components, protocols, and essential services like the
Domain Name System (DNS).

Computer Networking

What is a Computer Network?


A computer network is a collection of interconnected devices that share resources
and information. These devices can include computers, servers, printers, and
other hardware. Networks allow for the efficient exchange of data, enabling
various applications such as email, file sharing, and internet browsing.
How Does a Computer Network Work?
Basics building blocks of a Computer network are Nodes and Links. A Network
Node can be illustrated as Equipment for Data Communication like a Modem,
Router, etc., or Equipment of a Data Terminal like connecting two computers or
more. Link in Computer Networks can be defined as wires or cables or free space
of wireless networks.
The working of Computer Networks can be simply defined as rules or protocols
which help in sending and receiving data via the links which allow Computer
networks to communicate. Each device has an IP Address, that helps in identifying
a device.
What do Computer Networks do?
Computer networks first developed in 1950 for military and defense purpose. At
that time they are mainly used to send data through telephone lines and had
limited use in business or science.
Today computer networks are essential for businesses also. Modern networks
offer more than just connecting devices. They play a key role in helping businesses
adapt to the digital world and succeed. These networks have become more
flexible, automated, and secure, making them even more important in today’s
business environment.
Modern computer networks can:
• Work Virtually: The physical network can be divided into smaller virtual
networks. In these virtual networks, devices are connected and can send data
through multiple physical routes. For example, many business networks use
the internet this way.
• Connect on a Large Scale: Modern networks link many smaller, spread-out
networks into one big, powerful system. Automation and monitoring tools
help manage and adjust the network as needed, allowing it to grow or shrink
based on demand.
• Adapt Quickly: Many networks are controlled by software, so changes can be
made quickly through a digital dashboard. This allows traffic to be managed
easily.
• Keep Data Secure: Built-in security features like encryption and access
control protect data. Additional protections like antivirus software, firewalls,
and malware protection can be added to strengthen network security.
Basic Terminologies of Computer Networks
• Network: A network is a collection of computers and devices that are
connected together to enable communication and data exchange.
• Nodes: Nodes are devices that are connected to a network. These can include
computers, Servers, Printers, Routers, Switches, and other devices.
• Protocol: A protocol is a set of rules and standards that govern how data is
transmitted over a network. Examples of protocols include TCP/IP, HTTP,
and FTP.
• Topology: Network topology refers to the physical and logical arrangement
of nodes on a network. The common network topologies include bus, star,
ring, mesh, and tree.
• Service Provider Networks: These types of Networks give permission to
take Network Capacity and Functionality on lease from the Provider. Service
Provider Networks include Wireless Communications, Data Carriers, etc.
• IP Address: An IP address is a unique numerical identifier that is assigned to
every device on a network. IP addresses are used to identify devices and
enable communication between them.
• DNS: The Domain Name System (DNS) is a protocol that is used to translate
human-readable domain names (such as www.google.com) into IP addresses
that computers can understand.
• Firewall: A firewall is a security device that is used to monitor and control
incoming and outgoing network traffic. Firewalls are used to protect
networks from unauthorized access and other security threats.
Types of Enterprise Computer Networks
• LAN: A Local Area Network (LAN) is a network that covers a small area, such
as an office or a home. LANs are typically used to connect computers and
other devices within a building or a campus.
• WAN: A Wide Area Network (WAN) is a network that covers a large
geographic area, such as a city, country, or even the entire world. WANs are
used to connect LANs together and are typically used for long-distance
communication.
• Cloud Networks: Cloud Networks can be visualized with a Wide Area
Network (WAN) as they can be hosted on public or private cloud service
providers and cloud networks are available if there is a demand. Cloud
Networks consist of Virtual Routers, Firewalls, etc.
These are just a few basic concepts of computer networking. Networking is a vast
and complex field, and there are many more concepts and technologies involved
in building and maintaining networks. Now we are going to discuss some more
concepts on Computer Networking.
• Open system: A system that is connected to the network and is ready for
communication.
• Closed system: A system that is not connected to the network and can’t be
communicated with.
Types of Computer Network Architecture
Computer Network falls under these broad Categories:
• Client-Server Architecture: Client-Server Architecture is a type of Computer
Network Architecture in which Nodes can be Servers or Clients. Here, the
server node can manage the Client Node Behaviour.
• Peer-to-Peer Architecture: In P2P (Peer-to-Peer) Architecture, there is not
any concept of a Central Server. Each device is free for working as either client
or server.
Network Devices
An interconnection of multiple devices, also known as hosts, that are connected
using multiple paths for the purpose of sending/receiving data or media.
Computer networks can also include multiple devices/mediums which help in the
communication between two different devices; these are known as Network
devices and include things such as routers, switches, hubs, and bridges.

Network Devices

Network Topology
The Network Topology is the layout arrangement of the different devices in a
network. Some types of network topologies are:
• Bus Topology: In bus topology all devices are connected to a single central
cable called a bus. Data is sent along this cable and all devices share the same
connection. Simple and cheap to set up but if the main cable fails the whole
network goes down.
• Star Topology: In star topology all devices are connected to a central node
called hub or switch. The hub controls the flow of data between devices. If one
device fails the rest of the network is unaffected. But, if the central hub fails
the whole network stops working.
• Ring Topology: In ring topology devices are connected in a circular loop with
each device connected to two others. Data travels in one direction (or
sometimes both) passing through each device until it reaches its destination.
A failure in one device can affect the whole network.
• Mesh Topology: In mesh topology every device is connected to every other
device in the network. It provides multiple paths for data so if one path fails
another can take over.
• Tree Topology: Tree topology is the combination of star and bus topology.
Tree topology is good for organizing large networks and allows for easy
expansion.
• Hybrid Topology: Hybrid topology is the combination of two or more
different topologies (like star and mesh). It is flexible and can be customized
based on the network’s specific needs.

Network Topology

OSI Model
OSI stands for Open Systems Interconnection. It is a reference model that specifies
standards for communications protocols and also the functionalities of each
layer. The OSI has been developed by the International Organization For
Standardization and it is 7 layer architecture. Each layer of OSI has different
functions and each layer has to follow different protocols. The 7 layers are as
follows:
• Physical Layer
• Data link Layer
• Network Layer
• Transport Layer
• Session Layer
• Presentation Layer
• Application Layer
Network Protocols
A protocol is a set of rules or algorithms which define the way how two entities
can communicate across the network and there exists a different protocol defined
at each layer of the OSI model. A few such protocols are TCP, IP, UDP, ARP, DHCP,
FTP, and so on.
• Transmission Control Protocol/Internet Protocol (TCP/IP): TCP/IP is the
foundational protocol suite of the internet, enabling reliable communication.
TCP Ensures data is delivered reliably and in order and IP routes data packets
to their destination based on IP addresses.
• Hypertext Transfer Protocol (HTTP) and HTTPS: HTTP
and HTTPS protocols used for transmitting web pages. In
HTTP communication is unsecured and in HTTPS secured communication
using SSL/TLS encryption.
• Simple Mail Transfer Protocol (SMTP): SMTP protocol used to send
email. SMTP protocol works with other protocols like POP3 and IMAP for
email retrieval.
• File Transfer Protocol (FTP): FTP protocol used for transferring files
between computers. Includes commands for uploading, downloading, and
managing files on a remote server.
• Dynamic Host Configuration Protocol
(DHCP): DHCP protocol automatically assigns IP addresses to devices on a
network. Reduces manual configuration and IP address conflicts.
• Domain Name System (DNS): DNS Translates human-friendly domain
names into IP addresses. Ensures seamless navigation on the internet.
Unique Identifiers of Network
Hostname: Each device in the network is associated with a unique device name
known as Hostname. Type “hostname” in the command prompt(Administrator
Mode) and press ‘Enter’, this displays the hostname of your machine.
HostName

IP Address (Internet Protocol address): Also known as the Logical Address, the
IP Address is the network address of the system across the network. To identify
each device in the world-wide-web, the Internet Assigned Numbers Authority
(IANA) assigns an IPV4 (Version 4) address as a unique identifier to each device
on the Internet. The length of an IPv4 address is 32 bits, hence, we have 232 IP
addresses available. The length of an IPv6 address is 128 bits.
In Windows Type “ipconfig” in the command prompt and press ‘Enter’, this gives
us the IP address of the device. For Linux, Type “ifconfig” in the terminal and press
‘Enter’ this gives us the IP address of the device.
MAC Address (Media Access Control address): Also known as physical
address, the MAC Address is the unique identifier of each host and is associated
with its NIC (Network Interface Card). A MAC address is assigned to the NIC at
the time of manufacturing. The length of the MAC address is: 12-nibble/ 6 bytes/
48 bits Type “ipconfig/all” in the command prompt and press ‘Enter’, this gives
us the MAC address.
Port: A port can be referred to as a logical channel through which data can be
sent/received to an application. Any host may have multiple applications
running, and each of these applications is identified using the port number on
which they are running.
A port number is a 16-bit integer, hence, we have 216 ports available which are
categorized as shown below:
Port Types Range

Well known Ports 0 – 1023

Registered Ports 1024 – 49151

Ephemeral Ports 49152 – 65535

Number of ports: 65,536


Range: 0 – 65535
Type “netstat -a” in the command prompt and press ‘Enter’, this lists all the ports
being used.

List of Ports

Socket: The unique combination of IP address and Port number together is


termed a Socket.
Other Related Concepts
DNS Server: DNS stands for Domain Name System. DNS is basically a server that
translates web addresses or URLs (ex: www.google.com) into their corresponding
IP addresses. We don’t have to remember all the IP addresses of each and every
website. The command ‘nslookup’ gives you the IP address of the domain you are
looking for. This also provides information on our DNS Server. \
Domain IP Address

ARP: ARP stands for Address Resolution Protocol. It is used to convert an IP


address to its corresponding physical address(i.e., MAC Address). ARP is used by
the Data Link Layer to identify the MAC address of the Receiver’s machine.
RARP: RARP stands for Reverse Address Resolution Protocol. As the name
suggests, it provides the IP address of the device given a physical address as
input. But RARP has become obsolete since the time DHCP has come into the
picture.
The Domain Name System (DNS) is a critical component of computer networking.
It converts easily recognizable domain names, such as www.example.com, into
numerical IP addresses that computers use to identify each other on the network.
How DNS Works?
DNS works efficiently, translating user-friendly domain names into IP addresses,
allowing seamless navigation on the internet. Below step by step working of DNS:
• User Input: When a user enters a domain name in a browser, the system
needs to find its IP address.
• DNS Query: The user’s device sends a DNS query to the DNS resolver.
• Resolver Request: The DNS resolver checks its cache for the IP address. If
not found, it forwards the request to the root DNS server.
• Root DNS Server: The root DNS server provides the address of the TLD (Top-
Level Domain) server for the specific domain extension (e.g., .com).
• TLD DNS Server: The TLD server directs the resolver to the authoritative
DNS server for the actual domain.
• Authoritative DNS Server: The authoritative DNS server knows the IP
address for the domain and provides it to the resolver.
• Response to User: The resolver stores the IP address in its cache and sends it
to the user’s device.
• Access Website: With the IP address, the user’s device can access the desired
website.
Network Security
Ensuring the security of a network is crucial to protect data and resources from
unauthorized access and attacks. Key aspects of network security include:
• Firewalls: Devices or software that monitor and control incoming and
outgoing network traffic based on security rules.
• Encryption: The process of encoding data to prevent unauthorized access.
Commonly used in VPNs, HTTPS, and secure email.
• Intrusion Detection Systems (IDS): Tools that monitor network traffic for
suspicious activity and potential threats.
• Access Control: Mechanisms that restrict access to network resources based
on user identity and role.
• Regular Updates and Patching: Keeping software and hardware up to date
to protect against vulnerabilities.
Why Use Computer Networks?
Computer network play a important role in modern life. Here are some key
benefits of computer networks:
• Fast and Easy Communication: Networks enable all types of digital
communication, like emails, messaging, file sharing, video calls, and
streaming.
• More Storage Space: Suppose if we don’t have a cloud storage then we have
to store data in physical files that will consume a physical space so computer
network provide a storage for storing data.
• Easier Sharing of Information: Networks make it simpler for users and
teams to share resources and information. Teams can collaborate more easily,
and users get faster response from network devices.
• Better Security: Well designed networks are more reliable and give
businesses more options for keeping data safe. They come with built-in
security features like encryption and access controls to protect sensitive
information from cyber threats.
Conclusion
Understanding the basics of computer networking is essential in today’s
interconnected world. Networks enable the seamless exchange of information,
support countless applications, and underpin the functionality of the internet.
From different types of networks and their components to protocols and security
measures, a solid grasp of these concepts is foundational for anyone working in or
with technology. As technology evolves, so too will the complexity and capabilities
of computer networks, making continuous learning and adaptation crucial.
Frequently Asked Questions on Basics of Computer
Networking – FAQs
What is an IP address?
An IP (Internet Protocol) address is a unique identifier assigned to each device on a
network. It allows devices to locate and communicate with each other. There are two
types of IP addresses: IPv4 (e.g., 192.168.1.1) and IPv6 (e.g.,
2001:0db8:85a3:0000:0000:8a2e:0370:7334).
What is the difference between TCP and UDP?
• TCP (Transmission Control Protocol): A connection-oriented protocol that
ensures reliable and ordered delivery of data. It is used for applications where
data integrity is critical, like web browsing and email.
• UDP (User Datagram Protocol): A connectionless protocol that does not
guarantee delivery or order. It is used for applications where speed is more
important than reliability, like streaming and gaming.
What is a firewall?
A firewall is a network security device or software that monitors and controls
incoming and outgoing network traffic based on predefined security rules. It acts as
a barrier between a trusted internal network and untrusted external networks like
the internet.
What is a subnet mask?
A subnet mask is used in IP addressing to divide the network into sub-networks, or
subnets. It helps determine which portion of an IP address is the network address and
which part is the host address.
What is NAT (Network Address Translation)?
NAT is a method used by routers to translate private IP addresses within a local
network to a public IP address before sending data over the internet. This helps to
conserve IP addresses and add a layer of security by hiding internal network
addresses.
What is a MAC address?
A MAC (Media Access Control) address is a unique identifier assigned to a network
interface card (NIC) for communication on a physical network segment. It is a
hardware address that is unique to each network device..
What is latency in networking?
Latency is the time it takes for data to travel from the source to the destination across
a network. It is usually measured in milliseconds (ms) and can affect the performance
of networked applications.

Are you a student in Computer Science or an employed professional looking to


take up the GATE 2025 Exam? Of course, you can get a good score in it but to get
the best score our GATE CS/IT 2025 - Self-Paced Course is available on
GeeksforGeeks to help you with its preparation. Get comprehensive coverage
of all topics of GATE, detailed explanations, and practice questions for study.
Study at your pace. Flexible and easy-to-follow modules. Do well in GATE to
enhance the prospects of your career. Enroll now and let your journey to success
begin!

Types of Network Topology


Last Updated : 29 Oct, 2024


Network topology refers to the arrangement of different elements like nodes,
links, or devices in a computer network. Common types of network topology
include bus, star, ring, mesh, and tree topologies, each with its advantages and
disadvantages. In this article, we will discuss different types of network topology
in detail.
What is Network Topology?
Network topology is the way devices are connected in a network. It defines how
these components are connected and how data transter between the network.
Understanding the different types of network topologies can help in choosing the
right design for a specific network.
There are two major categories of Network Topology i.e. Physical Network
topology and Logical Network Topology. Physical Network Topology refers to the
actual structure of the physical medium for the transmission of data. Logical
network Topology refers to the transmission of data between devices present in
the network irrespective of the way devices are connected. The structure of the
network is important for the proper functioning of the network. one must choose
the most suitable topology as per their requirement.
Types of Network Topology
Below mentioned are the types of Network Topology
• Point to Point Topology
• Mesh Topology
• Star Topology
• Bus Topology
• Ring Topology
• Tree Topology
• Hybrid Topology
A strong understanding of network topologies is essential for competitive exams
like GATE, where computer networks are a significant subject. To deepen your
knowledge and enhance your exam preparation, consider enrolling in the GATE
CS Self-Paced Course . This course covers all critical networking concepts,
including detailed explanations of various network topologies, equipping you
with the expertise needed to excel in your exams.
Point to Point Topology
Point-to-point topology is a type of topology that works on the functionality of the
sender and receiver. It is the simplest communication between two nodes, in
which one is the sender and the other one is the receiver. Point-to-Point provides
high bandwidth.

Point to Point Topology

Mesh Topology
In a mesh topology, every device is connected to another device via a particular
channel. Every device is connected to another via dedicated channels. These
channels are known as links. In Mesh Topology, the protocols used are AHCP (Ad
Hoc Configuration Protocols), DHCP (Dynamic Host Configuration Protocol), etc.
Mesh Topology

• Suppose, the N number of devices are connected with each other in a mesh
topology, the total number of ports that are required by each device is N-1. In
Figure 1, there are 5 devices connected to each other, hence the total number
of ports required by each device is 4. The total number of ports required = N *
(N-1).
• Suppose, N number of devices are connected with each other in a mesh
topology, then the total number of dedicated links required to connect them
is N C 2 i.e. N(N-1)/2. In Figure 1, there are 5 devices connected to each other,
hence the total number of links required is 5*4/2 = 10.
Advantages of Mesh Topology
• Communication is very fast between the nodes.
• Mesh Topology is robust.
• The fault is diagnosed easily. Data is reliable because data is transferred
among the devices through dedicated channels or links.
• Provides security and privacy.
Disadvantages of Mesh Topology
• Installation and configuration are difficult.
• The cost of cables is high as bulk wiring is required, hence suitable for less
number of devices.
• The cost of maintenance is high.
A common example of mesh topology is the internet backbone, where various
internet service providers are connected to each other via dedicated channels.
This topology is also used in military communication systems and aircraft
navigation systems.
Star Topology
In Star Topology, all the devices are connected to a single hub through a cable. This
hub is the central node and all other nodes are connected to the central node. The
hub can be passive in nature i.e., not an intelligent hub such as broadcasting
devices, at the same time the hub can be intelligent known as an active hub. Active
hubs have repeaters in them. Coaxial cables or RJ-45 cables are used to connect
the computers. In Star Topology, many popular Ethernet LAN protocols are used
as CD(Collision Detection), CSMA (Carrier Sense Multiple Access), etc.

Star Topology

Advantages of Star Topology


• If N devices are connected to each other in a star topology, then the number of
cables required to connect them is N. So, it is easy to set up.
• Each device requires only 1 port i.e. to connect to the hub, therefore the total
number of ports required is N.
• It is Robust. If one link fails only that link will affect and not other than that.
• Easy to fault identification and fault isolation.
• Star topology is cost-effective as it uses inexpensive coaxial cable.
Disadvantages of Star Topology
• If the concentrator (hub) on which the whole topology relies fails, the whole
system will crash down.
• The cost of installation is high.
• Performance is based on the single concentrator i.e. hub.
A common example of star topology is a local area network (LAN) in an office
where all computers are connected to a central hub. This topology is also used in
wireless networks where all devices are connected to a wireless access point.
Bus Topology
Bus Topology is a network type in which every computer and network device is
connected to a single cable. It is bi-directional. It is a multi-point connection and a
non-robust topology because if the backbone fails the topology crashes. In Bus
Topology, various MAC (Media Access Control) protocols are followed by LAN
ethernet connections like TDMA, Pure Aloha, CDMA, Slotted Aloha, etc.

Bus Topology

Advantages of Bus Topology


• If N devices are connected to each other in a bus topology, then the number of
cables required to connect them is 1, known as backbone cable, and N drop
lines are required.
• Coaxial or twisted pair cables are mainly used in bus-based networks that
support up to 10 Mbps.
• The cost of the cable is less compared to other topologies, but it is used to
build small networks.
• Bus topology is familiar technology as installation and troubleshooting
techniques are well known.
• CSMA is the most common method for this type of topology.
Disadvantages of Bus Topology
• A bus topology is quite simpler, but still, it requires a lot of cabling.
• If the common cable fails, then the whole system will crash down.
• If the network traffic is heavy, it increases collisions in the network. To avoid
this, various protocols are used in the MAC layer known as Pure Aloha, Slotted
Aloha, CSMA/CD, etc.
• Adding new devices to the network would slow down networks.
• Security is very low.
A common example of bus topology is the Ethernet LAN, where all devices are
connected to a single coaxial cable or twisted pair cable. This topology is also used
in cable television networks.
Ring Topology
In a Ring Topology, it forms a ring connecting devices with exactly two
neighboring devices. A number of repeaters are used for Ring topology with a large
number of nodes, because if someone wants to send some data to the last node in
the ring topology with 100 nodes, then the data will have to pass through 99 nodes
to reach the 100th node. Hence to prevent data loss repeaters are used in the
network.
The data flows in one direction, i.e. it is unidirectional, but it can be made
bidirectional by having 2 connections between each Network Node, it is
called Dual Ring Topology. In-Ring Topology, the Token Ring Passing protocol is
used by the workstations to transmit the data.
Ring Topology

The most common access method of ring topology is token passing.


• Token passing: It is a network access method in which a token is passed
from one node to another node.
• Token: It is a frame that circulates around the network.
Operations of Ring Topology
• One station is known as a monitor station which takes all the responsibility
for performing the operations.
• To transmit the data, the station has to hold the token. After the transmission
is done, the token is to be released for other stations to use.
• When no station is transmitting the data, then the token will circulate in the
ring.
• There are two types of token release techniques: Early token
release releases the token just after transmitting the data and Delayed token
release releases the token after the acknowledgment is received from the
receiver.
Advantages of Ring Topology
• The data transmission is high-speed.
• The possibility of collision is minimum in this type of topology.
• Cheap to install and expand.
• It is less costly than a star topology.
Disadvantages of Ring Topology
• The failure of a single node in the network can cause the entire network to
fail.
• Troubleshooting is difficult in this topology.
• The addition of stations in between or the removal of stations can disturb the
whole topology.
• Less secure.

Tree Topology
Tree topology is the variation of the Star topology. This topology has a hierarchical
flow of data. In Tree Topology, protocols like DHCP and SAC (Standard
Automatic Configuration) are used.

Tree Topology

In tree topology, the various secondary hubs are connected to the central hub
which contains the repeater. This data flow from top to bottom i.e. from the central
hub to the secondary and then to the devices or from bottom to top i.e. devices to
the secondary hub and then to the central hub. It is a multi-point connection and a
non-robust topology because if the backbone fails the topology crashes.
Advantages of Tree Topology
• It allows more devices to be attached to a single central hub thus it decreases
the distance that is traveled by the signal to come to the devices.
• It allows the network to get isolated and also prioritize from different
computers.
• We can add new devices to the existing network.
• Error detection and error correction are very easy in a tree topology.
Disadvantages of Tree Topology
• If the central hub gets fails the entire system fails.
• The cost is high because of the cabling.
• If new devices are added, it becomes difficult to reconfigure.
A common example of a tree topology is the hierarchy in a large organization. At
the top of the tree is the CEO, who is connected to the different departments or
divisions (child nodes) of the company. Each department has its own hierarchy,
with managers overseeing different teams (grandchild nodes). The team members
(leaf nodes) are at the bottom of the hierarchy, connected to their respective
managers and departments.
Hybrid Topology
Hybrid Topology is the combination of all the various types of topologies we have
studied above. Hybrid Topology is used when the nodes are free to take any form.
It means these can be individuals such as Ring or Star topology or can be a
combination of various types of topologies seen above. Each individual topology
uses the protocol that has been discussed earlier.
Hybrid Topology

The above figure shows the structure of the Hybrid topology. As seen it contains
a combination of all different types of networks.
Advantages of Hybrid Topology
• This topology is very flexible .
• The size of the network can be easily expanded by adding new devices.
Disadvantages of Hybrid Topology
• It is challenging to design the architecture of the Hybrid Network.
• Hubs used in this topology are very expensive.
• The infrastructure cost is very high as a hybrid network requires a lot of
cabling and network devices .
A common example of a hybrid topology is a university campus network. The
network may have a backbone of a star topology, with each building connected to
the backbone through a switch or router. Within each building, there may be a bus
or ring topology connecting the different rooms and offices. The wireless access
points also create a mesh topology for wireless devices. This hybrid topology
allows for efficient communication between different buildings while providing
flexibility and redundancy within each building.
Why is Network Topology Important?
Network Topology is important because it defines how devices are connected
and how they communicate in the network. Here are some points that defines
why network topology is important.
• Network Performance: Upon choosing the appropriate topology as per
requirement, it helps in running the network easily and hence increases
network performance.
• Network Reliability: Some topologies like Star, Mesh are reliable as if one
connection fails, they provide an alternative for that connection, hence it
works as a backup.
• Network Expansion: Chosing correct topology helps in easier expansion of
Network as it helps in adding more devices to the network without disrupting
the actual network.
• Network Security: Network Topology helps in understanding how devices
are connected and hence provides a better security to the network.
Conclusion
In conclusion, network topologies play a crucial role in determining the efficiency
and reliability of a computer network. Each topology, whether it’s bus, star, ring,
mesh, or tree, offers unique benefits and potential drawbacks. By understanding
these different arrangements, network designers can choose the most appropriate
topology to meet the specific needs of their systems, ensuring optimal
performance and connectivity.
Frequently Asked Questions on Types of Network
Topology – FAQs
Which topology is best for large networks?
For large networks, mesh and tree topologies are often preferred. Mesh topology
offers high reliability and redundancy, while tree topology supports scalability and
efficient data organization.
Can different topologies be combined in a single network?
Yes, different topologies can be combined in a hybrid topology to take advantage of
the strengths of each type, improving overall network performance and reliability.
Which topology is the simplest and cheapest to set up?
Bus topology is the simplest and cheapest to set up, as it uses a single cable to
connect all devices. However, it’s better suited for smaller networks.
Why is hybrid topology used in large networks?
Hybrid topology combines the strengths of different topologies to suit complex or
large networks.
How do I choose the right network topology for my needs?
Choosing the right network topology depends on factors such as the size of your
network, budget, desired performance, and the need for reliability and scalability.
Assess your specific requirements to make an informed decision.

Are you a student in Computer Science or an employed professional looking to


take up the GATE 2025 Exam? Of course, you can get a good score in it but to get
the best score our GATE CS/IT 2025 - Self-Paced Course is available on
GeeksforGeeks to help you with its preparation. Get comprehensive coverage
of all topics of GATE, detailed explanations, and practice questions for study.
Study at your pace. Flexible and easy-to-follow modules. Do well in GATE to
enhance the prospects of your career. Enroll now and let your journey to success
begin!

Video | Network Topology | Computer Networks

Difference between Physical and Logical


Topology
Last Updated : 01 Mar, 2024


A Physical and Logical topologies are important concepts that govern the
formation and operation of networks. In this article we will see differences
between both topologies, and troubleshooting network infrastructure.
What is Physical Topology?
Physical topology indicates the arrangement of different elements of a network. It
reflects the physical layout of devices and cables to form a connected network. It
is concerned with the essentials of the network ignoring minute details like
transfer of data and device type. The pattern of arrangement of nodes (computers)
and network cables depends on the ease of installation and setup of the network.
It affects cost and bandwidth capacity based on a solution of devices. It takes into
account the placement of nodes and the distance between them. Devices can be
arranged to form a ring (Ring Topology) or linearly connected in a line called Bus
Topology.
Types of Physical Topology
The arrangement of a network that comprises nodes and connecting lines via
sender and receiver is referred to as Network Topology. On the basis of
arrangements, Physical Topology has several types:
1. Mesh Topology
2. Star Topology
3. Bus Topology
4. Ring Topology
5. Hybrid Topology
Advantages of Physical Topology
• Reliability: Some physical topologies, including the mesh topology, provide
redundancy, making sure that community connectivity is maintained although
a connection or device fails.
• Tangible Representation: Physical topology offers a concrete representation
of how devices are physically linked, aiding in troubleshooting and
maintainence responsibilities.
• Scalability: Certain physical topologies, like the star topology, provide
scalability, allowing for smooth expansion by means of including extra
devices.
Disadvantages of Physical Topology
• Vulnerability to Physical Damage: Physical topologies are liable to
disruptions resulting from physical damage to cables or networking
hardware.
• Limited Flexibility: Changing a network’s physical architecture can be
difficult and involve a significant amount of reconfiguration.
• Costly Implementation: Some physical topologies can be quite expensive to
build, especially if they include a lot of cables or redundant hardware.
What is Logical Topology?
Logical Topology reflects the arrangement of devices and their communication. It
is the transmission of data over physical topology. It is independent of physical
topology, irrespective of the arrangements of nodes. It is concerned with intricate
details of network like type of devices (switches, routers) chosen and their quality,
which affects rate and speed of data packets delivery. The logical topology ensures
optimal flow control that can be regulated within network. The data can either
flow in a linear pattern called Logical bus or in form of a circle Logical ring.
Types of Logical Topology
Logical topology refers to the manner in which the data is transported and the
network device structure is displayed. On the basis of data transfer, logical
topology have below mentioned types:
1. Ethernet
2. TCP/IP
3. OSI
Advantages of Logical Topology
• Flexibility: Logical topology allows community engineers to design and
configure networks based totally on logical necessities, without being
constrained by using physical limitations.
• Efficient Resource Utilization: Using logical topology to define efficient
information paths and routing configurations, the most efficient use of
resources is made possible.
• Ease of Implementation: Making changes or improvements to a logical
topology is frequently less difficult and disruptive than making changes to a
community’s physical layout.
Disadvantages of Logical Topology
• Complexity: Technical expertise and understanding may also be needed to
comprehend and manage the complexities of logical topology, which includes
protocols and routing configurations.
• Dependency on Protocols: Logical topology is contingent upon the proper
functioning of network protocols, making networks prone to issues arising
from protocol failures or misconfigurations.
• Potential Security Risks: Misconfigurations or vulnerabilities in logical
topology components, which include routing protocols, may leads to security
risk
Difference between Physical and Logical Topology
Physical Topology Logical Topology

Depicts logistics of network concerned with


Depicts physical layout of network.
transmission of data.

There is no interference and manipulation


The layout can be modified based on needs.
involved here.

This has major impact on cost, scalability This has major impact on speed and delivery
and bandwidth capacity of network based of data packets. It also handles flow control
on selection and availability of devices. and ordered delivery of data packets.
Physical Topology Logical Topology

It is actual route concerned with


It is a high level representation of data flow.
transmission.

Physical connection of the network. Data path followed of the network.

Question for Practice


If there are ‘N’ devices (nodes) in a network, what is the number of cable
links required for a fully connected mesh and a star topology respectively. [
ISRO CSE 2017]
(A) N(N-1)/2 , N-1
(B) N , N-1
(C) N-1 , N
(D) N-1 , N(N-1)/2
Solution: Every node in a fully connected mesh topology should be connected to every
other node, thus there will be = N (N − 1) / 2 links. while in star topology every device
is connected with the central hub, so N-1 links. Hence option (A) is correct.

Frequently Asked Question on Physical and Logical


Topology – FAQs
How do physical and logical topology interact within a network?
The physical connections between network devices are described by a physical
topology. We’re discussing wireless networking, wires, and other topics. How
network devices appear to be connected to one another is described by a logical
topology.
Which is more important in network design, physical or logical
topology?
Both physical and logical topology have their advantages and disadvantages, they
both are important for the network.
What does logical topology focus on?
The focus of logical topologies is on network data. Regardless of how the devices are
physically connected, the network’s topology is determined by the data flow inside it.
Which topology is most stable?
Physical Topology is more stable then Logical Topology.

Are you a student in Computer Science or an employed professional looking to


take up the GATE 2025 Exam? Of course, you can get a good score in it but to get
the best score our GATE CS/IT 2025 - Self-Paced Course is available on
GeeksforGeeks to help you with its preparation. Get comprehensive coverage
of all topics of GATE, detailed explanations, and practice questions for study.
Study at your pace. Flexible and easy-to-follow modules. Do well in GATE to
enhance the prospects of your career. Enroll now and let your journey to success
begin!

What is OSI Model? – Layers of OSI Model


Last Updated : 11 Nov, 2024


The OSI (Open Systems Interconnection) Model is a set of rules that explains
how different computer systems communicate over a network. OSI Model was
developed by the International Organization for Standardization (ISO). The
OSI Model consists of 7 layers and each layer has specific functions and
responsibilities.
This layered approach makes it easier for different devices and technologies to
work together. OSI Model provides a clear structure for data transmission and
managing network issues. The OSI Model is widely used as a reference to
understand how network systems function.
In this article, we will discuss the OSI Model and each layer of the OSI Model in
detail. We will also discuss the flow of data in the OSI Model and how the OSI
Model is different from the TCP/IP Model.
OSI Model

Layers of the OSI Model


There are 7 layers in the OSI Model and each layer has its specific role in
handling data. All the layers are mentioned below:
• Physical Layer
• Data Link Layer
• Network Layer
• Transport Layer
• Session Layer
• Presentation Layer
• Application Layer

Layer 1 – Physical Layer


The lowest layer of the OSI reference model is the Physical Layer. It is responsible
for the actual physical connection between the devices. The physical layer contains
information in the form of bits. Physical Layer is responsible for transmitting
individual bits from one node to the next. When receiving data, this layer will get
the signal received and convert it into 0s and 1s and send them to the Data Link
layer, which will put the frame back together. Common physical layer devices
are Hub, Repeater, Modem, and Cables.

Physical Layer

Functions of the Physical Layer


• Bit Synchronization: The physical layer provides the synchronization of the
bits by providing a clock. This clock controls both sender and receiver thus
providing synchronization at the bit level.
• Bit Rate Control: The Physical layer also defines the transmission rate i.e. the
number of bits sent per second.
• Physical Topologies: Physical layer specifies how the different,
devices/nodes are arranged in a network i.e. bus topology, star topology,
or mesh topology.
• Transmission Mode: Physical layer also defines how the data flows between
the two connected devices. The various transmission modes possible
are Simplex, half-duplex and full-duplex.
Layer 2 – Data Link Layer (DLL)
The data link layer is responsible for the node-to-node delivery of the message.
The main function of this layer is to make sure data transfer is error-free from one
node to another, over the physical layer. When a packet arrives in a network, it is
the responsibility of the DLL to transmit it to the Host using its MAC address.
Packet in the Data Link layer is referred to as Frame. Switches and Bridges are
common Data Link Layer devices.
The Data Link Layer is divided into two sublayers:
• Logical Link Control (LLC)
• Media Access Control (MAC)
The packet received from the Network layer is further divided into frames
depending on the frame size of the NIC(Network Interface Card). DLL also
encapsulates Sender and Receiver’s MAC address in the header.
The Receiver’s MAC address is obtained by placing an ARP(Address Resolution
Protocol) request onto the wire asking “Who has that IP address?” and the
destination host will reply with its MAC address.
Functions of the Data Link Layer
• Framing: Framing is a function of the data link layer. It provides a way for a
sender to transmit a set of bits that are meaningful to the receiver. This can be
accomplished by attaching special bit patterns to the beginning and end of the
frame.
• Physical Addressing: After creating frames, the Data link layer adds physical
addresses (MAC addresses) of the sender and/or receiver in the header of
each frame.
• Error Control: The data link layer provides the mechanism of error control in
which it detects and retransmits damaged or lost frames.
• Flow Control: The data rate must be constant on both sides else the data may
get corrupted thus, flow control coordinates the amount of data that can be
sent before receiving an acknowledgment.
• Access Control: When a single communication channel is shared by multiple
devices, the MAC sub-layer of the data link layer helps to determine which
device has control over the channel at a given time.
Layer 3 – Network Layer
The network layer works for the transmission of data from one host to the other
located in different networks. It also takes care of packet routing i.e. selection of
the shortest path to transmit the packet, from the number of routes available. The
sender and receiver’s IP address are placed in the header by the network layer.
Segment in the Network layer is referred to as Packet. Network layer is
implemented by networking devices such as routers and switches.
Functions of the Network Layer
• Routing: The network layer protocols determine which route is suitable from
source to destination. This function of the network layer is known as routing.
• Logical Addressing: To identify each device inter-network uniquely, the
network layer defines an addressing scheme. The sender and receiver’s IP
addresses are placed in the header by the network layer. Such an address
distinguishes each device uniquely and universally.
Layer 4 – Transport Layer
The transport layer provides services to the application layer and takes services
from the network layer. The data in the transport layer is referred to as Segments.
It is responsible for the end-to-end delivery of the complete message. The
transport layer also provides the acknowledgment of the successful data
transmission and re-transmits the data if an error is found. Protocols used in
Transport Layer are TCP, UDP NetBIOS, PPTP.
At the sender’s side, the transport layer receives the formatted data from the
upper layers, performs Segmentation, and also implements Flow and error
control to ensure proper data transmission. It also adds Source and
Destination port number in its header and forwards the segmented data to the
Network Layer.
• Generally, this destination port number is configured, either by default or
manually. For example, when a web application requests a web server, it
typically uses port number 80, because this is the default port assigned to web
applications. Many applications have default ports assigned.
At the Receiver’s side, Transport Layer reads the port number from its header
and forwards the Data which it has received to the respective application. It also
performs sequencing and reassembling of the segmented data.
Functions of the Transport Layer
• Segmentation and Reassembly: This layer accepts the message from the
(session) layer, and breaks the message into smaller units. Each of the
segments produced has a header associated with it. The transport layer at the
destination station reassembles the message.
• Service Point Addressing: To deliver the message to the correct process, the
transport layer header includes a type of address called service point address
or port address. Thus by specifying this address, the transport layer makes
sure that the message is delivered to the correct process.
Services Provided by Transport Layer
• Connection-Oriented Service
• Connectionless Service

Layer 5 – Session Layer


Session Layer in the OSI Model is responsible for the establishment of connections,
management of connections, terminations of sessions between two devices. It also
provides authentication and security. Protocols used in the Session Layer are
NetBIOS, PPTP.
Functions of the Session Layer
• Session Establishment, Maintenance, and Termination: The layer allows
the two processes to establish, use, and terminate a connection.
• Synchronization: This layer allows a process to add checkpoints that are
considered synchronization points in the data. These synchronization points
help to identify the error so that the data is re-synchronized properly, and
ends of the messages are not cut prematurely and data loss is avoided.
• Dialog Controller: The session layer allows two systems to start
communication with each other in half-duplex or full-duplex.
Example
Let us consider a scenario where a user wants to send a message through some
Messenger application running in their browser. The “Messenger” here acts as the
application layer which provides the user with an interface to create the data. This
message or so-called Data is compressed, optionally encrypted (if the data is
sensitive), and converted into bits (0’s and 1’s) so that it can be transmitted.

Communication in Session Layer

Layer 6 – Presentation Layer


The presentation layer is also called the Translation layer. The data from the
application layer is extracted here and manipulated as per the required format to
transmit over the network. Protocols used in the Presentation Layer
are JPEG, MPEG, GIF, TLS/SSL, etc.
Functions of the Presentation Layer
• Translation: For example, ASCII to EBCDIC.
• Encryption/ Decryption: Data encryption translates the data into another
form or code. The encrypted data is known as the ciphertext and the
decrypted data is known as plain text. A key value is used for encrypting as
well as decrypting data.
• Compression: Reduces the number of bits that need to be transmitted on the
network.
Layer 7 – Application Layer
At the very top of the OSI Reference Model stack of layers, we find the Application
layer which is implemented by the network applications. These applications
produce the data to be transferred over the network. This layer also serves as a
window for the application services to access the network and for displaying the
received information to the user. Protocols used in the Application layer
are SMTP, FTP, DNS, etc.

Application Layer
Functions of the Application Layer
The main functions of the application layer are given below.
• Network Virtual Terminal(NVT): It allows a user to log on to a remote host.
• File Transfer Access and Management(FTAM): This application allows a
user to access files in a remote host, retrieve files in a remote host, and
manage or control files from a remote computer.
• Mail Services: Provide email service.
• Directory Services: This application provides distributed database sources
and access for global information about various objects and services.
How Data Flows in the OSI Model?
When we transfer information from one device to another, it travels through 7
layers of OSI model. First data travels down through 7 layers from the sender’s
end and then climbs back 7 layers on the receiver’s end.
Data flows through the OSI model in a step-by-step process:
• Application Layer: Applications create the data.
• Presentation Layer: Data is formatted and encrypted.
• Session Layer: Connections are established and managed.
• Transport Layer: Data is broken into segments for reliable delivery.
• Network Layer: Segments are packaged into packets and routed.
• Data Link Layer: Packets are framed and sent to the next device.
• Physical Layer: Frames are converted into bits and transmitted physically.
Each layer adds specific information to ensure the data reaches its destination
correctly, and these steps are reversed upon arrival.
We can understand how data flows through OSI Model with the help of an example
mentioned below.
Let us suppose, Person A sends an e-mail to his friend Person B.
Step 1: Person A interacts with e-mail application like Gmail, outlook, etc.
Writes his email to send. (This happens at Application Layer).
Step 2: At Presentation Layer, Mail application prepares for data transmission
like encrypting data and formatting it for transmission.
Step 3: At Session Layer, There is a connection established between the sender
and receiver on the internet.
Step 4: At Transport Layer, Email data is broken into smaller segments. It adds
sequence number and error-checking information to maintain the reliability of the
information.
Step 5: At Network Layer, Addressing of packets is done in order to find the best
route for transfer.
Step 6: At Data Link Layer, data packets are encapsulated into frames, then MAC
address is added for local devices and then it checks for error using error
detection.
Step 7: At Physical Layer, Frames are transmitted in the form of electrical/
optical signals over a physical network medium like ethernet cable or WiFi.
After the email reaches the receiver i.e. Person B, the process will reverse and
decrypt the e-mail content. At last, the email will be shown on Person B email
client.
Protocols Used in the OSI Layers
Protocol
Layer Working Data Unit Protocols

Establishing Physical
1 – Physical
Connections between Bits USB, SONET/SDH, etc.
Layer
Devices.

2 – Data Link Node to Node Delivery


Frames Ethernet, PPP, etc.
Layer of Message.

Transmission of data
3 – Network from one host to IP, ICMP, IGMP, OSPF,
Packets
Layer another, located in etc.
different networks.

Take Service from Segments (for


4 – Transport Network Layer and TCP) or
TCP, UDP, SCTP, etc.
Layer provide it to the Datagrams
Application Layer. (for UDP)

Establishes Connection,
5 – Session Maintenance, Ensures
Data NetBIOS, RPC, PPTP, etc.
Layer Authentication and
Ensures security.

Data from the


application layer is
6 –
extracted and TLS/SSL, MIME, JPEG,
Presentation Data
manipulated in the PNG, ASCII, etc.
Layer
required format for
transmission.

7 – Helps in identifying the


FTP, SMTP, DNS, DHCP,
Application client and synchronizing Data
etc.
Layer communication.
Why Does The OSI Model Matter?
The OSI Model matters because it provides the user a clear structure of “how the
data moves in the network?”. As the OSI Model consists of 7 layers, each layer has
its specific role, and due to which it helps in understanding, identifying and solving
the complex network problems easily by focusing on one of the layers not the
entire network.
As the modern Internet does not prefer the OSI Model, but still, the OSI Model is
still very helpful for solving network problems. It helps people understanding
network concepts very easily.
Difference Between OSI and TCP/IP Model
OSI Model TCP/IP Model

OSI stands for Open Systems TCP/IP stands for Transmission Control
Interconnection. Protocol/Internet Protocol.

OSI model has 7 layers. TCP/IP model consists of 4 layers.

Package delivery is guaranteed in OSI Package delivery is not guaranteed in the


Model. TCP/IP Model.

In the OSI model, Only layers 1,2 and 3 are All layers of the TCP/IP model are needed for
necessary for data transmission. data transmission.

Protocols at each layer is independent of Layers are integrated, some layers are
the other layer. required by other layers of TCP/IP model.

OSI Model is a conceptual framework, less Widely used in actual networks like Internet
used in practical applications. and Communication Systems.
OSI vs TCP/IP

Advantages of OSI Model


The OSI Model defines the communication of a computing system into 7 different
layers. Its advantages include:
• It divides network communication into 7 layers which makes it easier to
understand and troubleshoot.
• It standardizes network communications, as each layer has fixed functions
and protocols.
• Diagnosing network problems is easier with the OSI model.
• It is easier to improve with advancements as each layer can get updates
separately.
Disadvantages of OSI Model
• The OSI Model has seven layers, which can be complicated and hard to
understand for beginners.
• In real-life networking, most systems use a simpler model called the Internet
protocol suite (TCP/IP), so the OSI Model is not always directly applicable.
• Each layer in the OSI Model adds its own set of rules and operations, which
can make the process more time-consuming and less efficient.
• The OSI Model is more of a theoretical framework, meaning it’s great for
understanding concepts but not always practical for implementation.
Conclusion
In conclusion, the OSI (Open Systems Interconnection) model helps us understand
how data moves in networks. It consists of seven distinct layers: Physical, Data
Link, Network, Transport, Session, Presentation, and Application. Each layer has
specific responsibilities and interacts with the layers directly above and below it.
Since it is a conceptual model, but the OSI framework is still widely used to
troubleshoot and understand networking issues.
Frequently Asked Questions on OSI Model – FAQs
Can OSI layers work independently?
No, OSI layers do not work independently. Each layer depends on the services
provided by the layer below it and, in turn, provides services to the layer above it.
This layered approach ensures that data is transmitted smoothly from the source to
the destination.
How does the OSI Model help in troubleshooting network issues?
By breaking down communication into layers, the OSI Model helps network
administrators isolate problems more easily.
What happens if a layer in the OSI Model fails?
If a particular OSI layer fails, data transmission may be disrupted or fail entirely.
Network administrator will check layer by layer to identify and resolve the issue,
make sure that each layer is functioning correctly or not.
How does DNS fit into the OSI Model?
The Domain Name System (DNS) operates at Layer 7 (Application Layer). It
translates domain names into IP addresses, facilitating communication between
users and services across the network.

Physical Layer in OSI Model


Last Updated : 03 Oct, 2024


The physical Layer is the bottom-most layer in the Open System
Interconnection (OSI) Model which is a physical and electrical
representation of the system. It consists of various network components such
as power plugs, connectors, receivers, cable types, etc. The physical layer
sends data bits from one device(s) (like a computer) to another device(s). The
physical Layer defines the types of encoding (that is how the 0’s and 1’s are
encoded in a signal). The physical Layer is responsible for the communication
of the unstructured raw data streams over a physical medium.

Functions Performed by Physical Layer


The following are some important and basic functions that are performed by
the Physical Layer of the OSI Model –
1. The physical layer maintains the data rate (how many bits a sender can
send per second).
2. It performs the Synchronization of bits.
3. It helps in Transmission Medium decisions (direction of data transfer).
4. It helps in Physical Topology (Mesh, Star, Bus, Ring) decisions (Topology
through which we can connect the devices with each other).
5. It helps in providing Physical Medium and Interface decisions.
6. It provides two types of configuration Point Point configuration and Multi-
Point configuration.
7. It provides an interface between devices (like PCs or computers) and
transmission medium.
8. It has a protocol data unit in bits.
9. Hubs, Ethernet, etc. device is used in this layer.
10. This layer comes under the category of Hardware Layers (since the
hardware layer is responsible for all the physical connection
establishment and processing too).
11. It provides an important aspect called Modulation, which is the process
of converting the data into radio waves by adding the information to an
electrical or optical nerve signal.
12. It also provides a Switching mechanism wherein data packets can be
forwarded from one port (sender port) to the leading destination port.
Physical Topologies
Physical Topology or Network Topology is the Geographical Representation
of Linking devices. Following are the four types of physical topology-
1. Mesh Topology: In a mesh topology, each and every device should have
a dedicated point-to-point connection with each and every other device in
the network. Here there is more security of data because there is a
dedicated point-to-point connection between two devices. Mesh Topology
is difficult to install because it is more complex.
2. Star Topology: In star topology , the device should have a dedicated
point-to-point connection with a central controller or hub. Star Topology is
easy to install and reconnect as compared to Mesh Topology. Star
Topology doesn’t have Fault Tolerance Technique.
3. Bus Topology: In a bus topology , multiple devices are connected
through a single cable that is known as backbone cable with the help of
tap and drop lines. It is less costly as compared to Mesh Topology and
Star Topology. Re-connection and Re-installation are difficult.
4. Ring Topology: In a ring topology , each device is connected with
repeaters in a circle-like ring that’s why it is called Ring Topology. In Ring
Topology, a device can send the data only when it has a token, without a
token no device can send the data, and a token is placed by Monitor in
Ring Topology.
Line Configuration
• Point-to-Point configuration: In Point-to-Point configuration, there is a
line (link) that is fully dedicated to carrying the data between two devices.
• Multi-Point configuration: In a Multi-Point configuration, there is a line
(link) through which multiple devices are connected.
Modes of Transmission Medium
1. Simplex mode: In this mode, out of two devices, only one device can
transmit the data, and the other device can only receive the data.
Example- Input from keyboards, monitors, TV broadcasting, Radio
broadcasting, etc.
2. Half Duplex mode: In this mode, out of two devices, both devices can
send and receive the data but only one at a time not simultaneously.
Examples- Walkie-Talkie, Railway Track, etc.
3. Full-Duplex mode: In this mode, both devices can send and receive the
data simultaneously. Examples- Telephone Systems, Chatting
applications, etc.
Physical Layer Protocols Examples
Typically, a combination of hardware and software programming makes up
the physical layer. It consists of several protocols that control data
transmissions on a network. The following are some examples of Layer 1
protocols:
• Ethernet with 1000BASE-T.
• Ethernet with 1000BASE-SX.
• Ethernet at 100BaseT.
• Synchronous Digital Hierarchy/Optical Synchronisation.
• Physical-layer variations in 802.11.
• Bluetooth.
• Networking for controllers.
• U.S. Serial Bus.
Frequently Asked Questions
Q.1: What is the Physical layer in the OSI model?
Answer:

Video | Physical Layer in OSI Model | Computer Network

The Physical layer is the first layer in the OSI (Open Systems
Interconnection) model, which is a conceptual framework that standardizes
the functions of a communication system. The Physical layer deals with the
physical transmission of data bits over a communication channel. It defines
the electrical, mechanical, and procedural aspects of transmitting raw data
between network devices. It primarily focuses on converting digital data into
a format suitable for transmission and ensuring reliable and efficient
communication at the physical level.
Q.2: What are the primary functions of the Physical layer?
Answer:
The main functions of the Physical layer include:
Encoding and signaling: It defines the method of encoding digital data into
electrical, optical, or radio signals for transmission over the physical medium.
Physical media: It specifies the characteristics of the physical media used for
data transmission, such as cables, fiber optics, or wireless channels.
Data transmission: It establishes the rules for transmitting raw data bits over
the physical medium, including aspects like bit synchronization, line coding,
and error detection.
Physical topologies: It defines the physical arrangement or layout of network
devices and how they are connected, such as bus, star, ring, or mesh
topologies.
Transmission modes: It describes the ways in which data is transmitted
between devices, such as simplex (one-way), half-duplex (two-way but not
simultaneously), or full-duplex (two-way simultaneously).
Are you a student in Computer Science or an employed professional looking
to take up the GATE 2025 Exam? Of course, you can get a good score in it
but to get the best score our GATE CS/IT 2025 - Self-Paced Course is
available on GeeksforGeeks to help you with its preparation. Get
comprehensive coverage of all topics of GATE, detailed explanations,
and practice questions for study. Study at your pace. Flexible and easy-to-
follow modules. Do well in GATE to enhance the prospects of your career.
Enroll now and let your journey to success begin!

Data Link Layer


Last Updated : 30 Sep, 2024


The data link layer is the second layer from the bottom in the OSI (Open System
Interconnection) network architecture model. It is responsible for the node-to-
node delivery of data. Its major role is to ensure error-free transmission of
information. DLL is also responsible for encoding, decoding, and organizing the
outgoing and incoming data.
This is considered the most complex layer of the OSI model as it hides all the
underlying complexities of the hardware from the other above layers. In this
article, we will discuss Data Link Layer in Detail along with its functions, and sub-
layers.
OSI Model: Data Link Layer

Sub-Layers of The Data Link Layer


The data link layer is further divided into two sub-layers, which are as follows:
Logical Link Control (LLC)
This sublayer of the data link layer deals with multiplexing, the flow of data among
applications and other services, and LLC is responsible for providing error
messages and acknowledgments as well.
Media Access Control (MAC)
MAC sublayer manages the device’s interaction, responsible for addressing
frames, and also controls physical media access.
The data link layer receives the information in the form of packets from the
Network layer, it divides packets into frames and sends those frames bit-by-bit to
the underlying physical layer.
Functions of The Data-link Layer
There are various benefits of data link layers s let’s look into it.

Framing
The packet received from the Network layer is known as a frame in the Data link
layer. At the sender’s side, DLL receives packets from the Network layer and
divides them into small frames, then, sends each frame bit-by-bit to the physical
layer. It also attaches some special bits (for error control and addressing) at the
header and end of the frame. At the receiver’s end, DLL takes bits from the Physical
layer organizes them into the frame, and sends them to the Network layer.
Addressing
The data link layer encapsulates the source and destination’s MAC address/
physical address in the header of each frame to ensure node-to-node delivery.
MAC address is the unique hardware address that is assigned to the device while
manufacturing.
Error Control
Data can get corrupted due to various reasons like noise, attenuation, etc. So, it is
the responsibility of the data link layer, to detect the error in the transmitted data
and correct it using error detection and correction techniques respectively. DLL
adds error detection bits into the frame’s header, so that receiver can check
received data is correct or not. It adds reliability to phyiscal layer by adding
mechansims to detect and retransmit damaged or lost frames.
Flow Control
If the receiver’s receiving speed is lower than the sender’s sending speed, then this
can lead to an overflow in the receiver’s buffer and some frames may get lost. So,
it’s the responsibility of DLL to synchronize the sender’s and receiver’s speeds and
establish flow control between them.
Access Control
When multiple devices share the same communication channel there is a high
probability of collision, so it’s the responsibility of DLL to check which device has
control over the channel and CSMA/CD and CSMA/CA can be used to avoid
collisions and loss of frames in the channel.
Protocols in Data link layer
There are various protocols in the data link layer, which are as follows:
• Synchronous Data Link Protocol (SDLC)
• High-Level Data Link Protocol (HDLC)
• Serial Line Interface Protocol (SLIP) for encoding
• Point to Point Protocol (PPP)
• Link Access Procedure (LAP)
• Link Control Protocol (LCP)
• Network Control Protocol (NCP)

Conclusion
In conclusion, the Data Link Layer is essential for ensuring that data is transferred
reliably and accurately across a network. It handles error detection and
correction, manages data frame sequencing, and provides access to the physical
network. By organizing data into frames and controlling how devices on the
network communicate, the Data Link Layer plays a crucial role in maintaining
smooth and efficient network operations.
Frequently Asked Questions on Data Link Layer – FAQs
What is the purpose of framing in the Data Link Layer?
Framing involves encapsulating data into frames with headers and trailers, allowing
the receiver to identify the start and end of each frame and to distinguish between
different frames.
What is MAC address in the Data Link Layer?
MAC (Media Access Control) address is a unique hardware address assigned to
network interfaces at the Data Link Layer. It is used to identify devices on a network.
What is the difference between a MAC address and an IP address?
A MAC address is a hardware address associated with a network interface card, while
an IP address is a logical address used for routing data packets in a network. MAC
addresses are used at the Data Link Layer, and IP addresses are used at the Network
Layer.
Session Layer in OSI model
Last Updated : 12 Jan, 2022


Prerequisite : OSI Layer
Introduction :
The Session Layer is the 5th layer in the Open System Interconnection (OSI)
model. This layer allows users on different machines to establish active
communications sessions between them. It is responsible for establishing,
maintaining, synchronizing, terminating sessions between end-user
applications. In Session Layer, streams of data are received and further
marked, which is then resynchronized properly, so that the ends of the
messages are not cut initially and further data loss is avoided. This layer
basically establishes a connection between the session entities. This layer
handles and manipulates data which it receives from the Session Layer as
well as from the Presentation Layer.
Application Layer
Presentation Layer
Present Layer=> Session Layer
Transport Layer
Network Layer
Data Layer
Physical Layer
Working of Session Layer :
Session Layer, which is the 5th layer in the OSI model, uses the services
provided by The transport layer, enables applications to establish and
maintain sessions and to synchronize the sessions.
Now, in order to establish a session connection, several things should be
followed.
First thing is we should map the session address to the shipping address.
The second thing is that we need to select the required transport quality of
service (also referred as QoS) parameters. Next thing is we need to take
care of the negotiations which should happen between session parameters.
Then we further need to transmit limited transparent user data. Then at last,
we need to monitor Data Transfer phase properly. The ability to send larger
amount of data files is extremely important and a necessary thing too.
Functions of Session Layer :
The session layer being the fifth layer in the OSI model performs several
different as well as important functions which are need for establishing as
well as maintaining a safe and secure connection.
Pause
Unmute
Pause
Unmute

Data from Presentation Layer <=> Session layer <=> Data from
Transport Layer
Following are some of the functions which are performed by Session Layer –
• Session Layer works as a dialog controller through which it allows
systems to communicate in either half-duplex mode or full duplex mode of
communication.
• This layer is also responsible for token management, through which it
prevents two users to simultaneously access or attempting the same
critical operation.
• This layer allows synchronization by allowing the process of adding
checkpoints, which are considered as synchronization points to the
streams of data.
• This layer is also responsible for session checkpointing and recovery.
• This layer basically provides a mechanism of opening, closing and
managing a session between the end-user application processes.
• The services offered by Session Layer are generally implemented in
application environments using remote procedure calls (RPCs).
• The Session Layer is also responsible for synchronizing information from
different sources.
• This layer also controls single or multiple connections for each-end user
application and directly communicates with both Presentation and
transport layers.
• Session Layer creates procedures for checkpointing followed by
adjournment, restart and termination.
• Session Layer uses checkpoints to enable communication sessions which
are to be resumed from that particular checkpoint at which communication
failure has occurred.
• The session Layer is responsible for fetching or receiving data information
from its previous layer (transport layer) and further sends data to the layer
after it (presentation layer).
Session Layer Protocols :
Session Layer uses some protocols which are required for safe, secure and
accurate communication which exists between two-ender user applications.
Following are some of the protocols provided or used by the Session Layer –
• AppleTalk Data Stream Protocol (ADSP): ADSP is that type of protocol
which was developed by Apple Inc. and it includes a number of features
that allow local area networks to be connected with no prior setup. This
protocol was released in 1985.
This protocol rigorously followed the OSI model of protocol layering.
ADSP itself has two protocols named: AppleTalk Address Resolution
Protocol (AARP) and Name Binding Protocol (NBP), both aimed at
making system self-configuring.
• Real-time Transport Control Protocol (RTCP): RTCP is a protocol
which provides out-of-band statistics and control information for an RTP
(Real-time Transport Protocol) session. RTCP’s primary function is to
provide feedback on the quality of service (QoS) in media distribution by
periodically sending statistical information such as transmitted octet and
packet counts or packet loss to the participants in the streaming
multimedia session.
• Point-to-Point Tunneling Protocol (PPTP): PPTP is a protocol which
provides a method for implementing virtual private networks. PPTP uses a
TCP control channel and a Generic Routing Encapsulation tunnel to
encapsulate PPP (Point-to-Point Protocol) packets This protocol provides
security levels and remote access levels comparable with typical VPN
(Virtual Private Network) products.
• Password Authentication Protocol (PAP): Password Authentication
Protocol is a password-based authentication protocol used by Point to
Point Protocol (PPP) to validate users. Almost all network operating
systems, remote servers support PAP. PAP authentication is done at the
time of the initial link establishment and verifies the identity of the client
using a two-way handshake (Client-sends data and server in return sends
Authentication-ACK (Acknowledgement) after the data sent by client is
verified completely).
• Remote Procedure Call Protocol (RPCP): Remote Procedure Call
Protocol (RPCP) is a protocol that is used when a computer program
causes a procedure (or a sub-routine) to execute in a different address
space without the programmer explicitly coding the details for the remote
interaction. This is basically the form of client-server interaction, typically
implemented via a request-response message-passing system.
• Sockets Direct Protocol (SDP): Sockets Direct Protocol (SDP) is a
protocol that supports streams of sockets over Remote Direct Memory
Access (RDMA) network fabrics.
The purpose of SDP is to provide an RDMA-accelerated alternative to the
TCP protocol. The primary goal is to perform one particular thing in such
a manner which is transparent to the application.

Presentation Layer in OSI model


Last Updated : 02 Aug, 2022


Prerequisite : OSI Model
Introduction : Presentation Layer is the 6th layer in the Open System
Interconnection (OSI) model. This layer is also known as Translation layer, as
this layer serves as a data translator for the network. The data which this layer
receives from the Application Layer is extracted and manipulated here as per the
required format to transmit over the network. The main responsibility of this
layer is to provide or define the data format and encryption. The presentation
layer is also called as Syntax layer since it is responsible for maintaining the
proper syntax of the data which it either receives or transmits to other layer(s).
Application Layer
Present Layer=> Presentation Layer
Session Layer
Transport Layer
Network Layer
Data Layer
Physical Layer
Functions of Presentation Layer :
Data from Application Layer <=> Presentation layer <=> Data from
Session Layer
The presentation layer, being the 6th layer in the OSI model, performs several
types of functions, which are described below-
• Presentation layer format and encrypts data to be sent across the network.
• This layer takes care that the data is sent in such a way that the receiver will
understand the information (data) and will be able to use the data efficiently
and effectively.
• This layer manages the abstract data structures and allows high-level data
structures (example- banking records), which are to be defined or exchanged.
• This layer carries out the encryption at the transmitter and decryption at the
receiver.
• This layer carries out data compression to reduce the bandwidth of the data
to be transmitted (the primary goal of data compression is to reduce the
number of bits which is to be transmitted).
• This layer is responsible for interoperability (ability of computers to exchange
and make use of information) between encoding methods as different
computers use different encoding methods.
• This layer basically deals with the presentation part of the data.
• Presentation layer, carries out the data compression (number of bits
reduction while transmission), which in return improves the data throughput.
• This layer also deals with the issues of string representation.
• The presentation layer is also responsible for integrating all the formats into a
standardized format for efficient and effective communication.
• This layer encodes the message from the user-dependent format to the
common format and vice-versa for communication between dissimilar
systems.
• This layer deals with the syntax and semantics of the messages.
• This layer also ensures that the messages which are to be presented to the
upper as well as the lower layer should be standardized as well as in an
accurate format too.
• Presentation layer is also responsible for translation, formatting, and delivery
of information for processing or display.
• This layer also performs serialization (process of translating a data structure
or an object into a format that can be stored or transmitted easily).
Features of Presentation Layer in the OSI model: Presentation layer, being the
6th layer in the OSI model, plays a vital role while communication is taking place
between two devices in a network.
List of features which are provided by the presentation layer are:
• Presentation layer could apply certain sophisticated compression techniques,
so fewer bytes of data are required to represent the information when it is
sent over the network.
• If two or more devices are communicating over an encrypted connection, then
this presentation layer is responsible for adding encryption on the sender’s
end as well as the decoding the encryption on the receiver’s end so that it can
represent the application layer with unencrypted, readable data.
• This layer formats and encrypts data to be sent over a network, providing
freedom from compatibility problems.
• This presentation layer also negotiates the Transfer Syntax.
• This presentation layer is also responsible for compressing data it receives
from the application layer before delivering it to the session layer (which is
the 5th layer in the OSI model) and thus improves the speed as well as the
efficiency of communication by minimizing the amount of the data to be
transferred.
Working of Presentation Layer in the OSI model :
Presentation layer in the OSI model, as a translator, converts the data sent by the
application layer of the transmitting node into an acceptable and compatible data
format based on the applicable network protocol and architecture. Upon arrival
at the receiving computer, the presentation layer translates data into an
acceptable format usable by the application layer. Basically, in other words, this
layer takes care of any issues occurring when transmitted data must be viewed in
a format different from the original format. Being the functional part of the OSI
mode, the presentation layer performs a multitude (large number of) data
conversion algorithms and character translation functions. Mainly, this layer is
responsible for managing two network characteristics: protocol (set of rules) and
architecture.
Presentation Layer Protocols :
Presentation layer being the 6th layer, but the most important layer in the OSI
model performs several types of functionalities, which makes sure that data
which is being transferred or received should be accurate or clear to all the
devices which are there in a closed network.
Presentation Layer, for performing translations or other specified functions,
needs to use certain protocols which are defined below –
• Apple Filing Protocol (AFP): Apple Filing Protocol is the proprietary
network protocol (communications protocol) that offers services to macOS or
the classic macOS. This is basically the network file control protocol
specifically designed for Mac-based platforms.
• Lightweight Presentation Protocol (LPP): Lightweight Presentation
Protocol is that protocol which is used to provide ISO presentation services on
the top of TCP/IP based protocol stacks.
• NetWare Core Protocol (NCP): NetWare Core Protocol is the network
protocol which is used to access file, print, directory, clock synchronization,
messaging, remote command execution and other network service functions.
• Network Data Representation (NDR): Network Data Representation is
basically the implementation of the presentation layer in the OSI model,
which provides or defines various primitive data types, constructed data
types and also several types of data representations.
• External Data Representation (XDR): External Data Representation (XDR)
is the standard for the description and encoding of data. It is useful for
transferring data between computer architectures and has been used to
communicate data between very diverse machines. Converting from local
representation to XDR is called encoding, whereas converting XDR into local
representation is called decoding.
• Secure Socket Layer (SSL): The Secure Socket Layer protocol provides
security to the data that is being transferred between the web browser and
the server. SSL encrypts the link between a web server and a browser, which
ensures that all data passed between them remains private and free from
attacks.

Application Layer in OSI Model


Last Updated : 03 Oct, 2024


The Application Layer of OSI (Open System Interconnection) model, is the top
layer in this model and takes care of network communication. The application
layer provides the functionality to send and receive data from users. It acts as the
interface between the user and the application. The application provides services
like file transmission, mail service, and many more.
In this article we will explore the application layer in the OSI model, application
layer functions, the working of the application layer, and services provided by the
application layer.
Table of Content
• What is Application Layer in OSI Model?
• Functions of Application Layer
• Working of Application Layer in OSI Model
• Features Provided by Application Layer Protocols
• Services Provided by Application Layer Protocols
• Application Layer Protocols
What is an Application Layer in OSI Model?
Application Layer is the topmost layer in the Open System Interconnection (OSI)
model. This layer provides several ways for manipulating the data (information)
which actually enables any type of user to access network with ease. This layer
also makes a request to its bottom layer, which is presentation layer for receiving
various types of information from it.
The Application Layer interface directly interacts with application and provides
common web application services. This layer is basically highest level of open
system, which provides services directly for application process.
Application Layer
Presentation LayerSession LayerTransport LayerNetwork LayerData
LayerPhysical Layer
Functions of Application Layer
The Application Layer, as discussed above, being topmost layer in OSI model,
performs several kinds of functions which are requirement in any kind of
application or communication process. Following are list of functions which are
performed by Application Layer of OSI Model:
Data from User <=> Application layer <=> Data from Presentation Layer
• Application Layer provides a facility by which users can forward several
emails and it also provides a storage facility.
• This layer allows users to access, retrieve and manage files in a remote
computer.
• It allows users to log on as a remote host.
• This layer provides access to global information about various services.
• This layer provides services which include: e-mail, transferring files,
distributing results to the user, directory services, network resources and so
on.
• It provides protocols that allow software to send and receive information and
present meaningful data to users.
• It handles issues such as network transparency, resource allocation and so on.
• This layer serves as a window for users and application processes to access
network services.
• Application Layer is basically not a function, but it performs application layer
functions.
• The application layer is actually an abstraction layer that specifies the shared
protocols and interface methods used by hosts in a communication network.
• Application Layer helps us to identify communication partners, and
synchronizing communication.
• This layer allows users to interact with other software applications.
• In this layer, data is in visual form, which makes users truly understand data
rather than remembering or visualize the data in the binary format (0’s or
1’s).
• This application layer basically interacts with Operating System (OS) and thus
further preserves the data in a suitable manner.
• This layer also receives and preserves data from it’s previous layer, which is
Presentation Layer (which carries in itself the syntax and semantics of the
information transmitted).
• The protocols which are used in this application layer depend upon what
information users wish to send or receive.
• This application layer, in general, performs host initialization followed by
remote login to hosts.
Working of Application Layer in OSI Model
The application layer in the OSI model generally acts only like the interface which
is responsible for communicating with host-based and user applications. This is in
contrast with TCP/IP protocol, wherein the layers below the application layer,
which is Session Layer and Presentation layer, are clubbed together and form a
simple single layer which is responsible for performing the functions, which
includes controlling the dialogues between computers, establishing as well as
maintaining as well as ending a particular session, providing data compression
and data encryption and so on.
Working of Application Layer
• At first, client sends a command to server and when server receives that
command, it allocates port number to client.
• Thereafter, the client sends an initiation connection request to server and
when server receives request, it gives acknowledgement (ACK) to client
through client has successfully established a connection with the server.
• Therefore, now client has access to server through which it may either ask
server to send any types of files or other documents or it may upload some
files or documents on server itself.
Features Provided by Application Layer Protocols
To ensure smooth communication, application layer protocols are implemented
the same on source host and destination host.
The following are some of the features which are provided by Application layer
protocols-
• The Application Layer protocol defines process for both parties which are
involved in communication.
• These protocols define the type of message being sent or received from any
side (either source host or destination host).
• These protocols also define basic syntax of the message being forwarded or
retrieved.
• These protocols define the way to send a message and the expected response.
• These protocols also define interaction with the next level.

Services Provided by Application Layer


The services provided by application layer in OSI model are:
• It provides interface between user and application.
• It is used for remote login.
• It is used for file transfer.
• It is used for mail services and transfers.
• It is also used to transfer multimedia files.
• It is used for resource sharing.
• It is used for data synchronization.
• It is used for authentication services.

Application Layer Protocols


The application layer provides several protocols which allow any software to
easily send and receive information and present meaningful data to its users. The
following are some of the application layer protocols.
• TELNET: Telnet stands for Telecommunications Network. This protocol is
used for managing files over the Internet. It allows the Telnet clients to access
the resources of Telnet server. Telnet uses port number 23.
• DNS: DNS stands for Domain Name System. The DNS service translates the
domain name (selected by user) into the corresponding IP address. For
example- If you choose the domain name as www.abcd.com, then DNS must
translate it as 192.36.20.8 (random IP address written just for understanding
purposes). DNS protocol uses the port number 53.
• DHCP: DHCP stands for Dynamic Host Configuration Protocol. It provides IP
addresses to hosts. Whenever a host tries to register for an IP address with
the DHCP server, DHCP server provides lots of information to the
corresponding host. DHCP uses port numbers 67 and 68.
• FTP: FTP stands for File Transfer Protocol. This protocol helps to transfer
different files from one device to another. FTP promotes sharing of files via
remote computer devices with reliable, efficient data transfer. FTP uses port
number 20 for data access and port number 21 for data control.
• SMTP: SMTP stands for Simple Mail Transfer Protocol. It is used to transfer
electronic mail from one user to another user. SMTP is used by end users to
send emails with ease. SMTP uses port numbers 25 and 587.
• HTTP: HTTP stands for Hyper Text Transfer Protocol. It is the foundation of
the World Wide Web (WWW). HTTP works on the client server model. This
protocol is used for transmitting hypermedia documents like HTML. This
protocol was designed particularly for the communications between the web
browsers and web servers, but this protocol can also be used for several other
purposes. HTTP is a stateless protocol (network protocol in which a client
sends requests to server and server responses back as per the given state),
which means the server is not responsible for maintaining the previous
client’s requests. HTTP uses port number 80.
• NFS: NFS stands for Network File System. This protocol allows remote hosts
to mount files over a network and interact with those file systems as though
they are mounted locally. NFS uses the port number 2049.
• SNMP: SNMP stands for Simple Network Management Protocol. This protocol
gathers data by polling the devices from the network to the management
station at fixed or random intervals, requiring them to disclose certain
information. SNMP uses port numbers 161 (TCP) and 162 (UDP).
Conclusion
From the above discussion we can conclude that application layer is the topmost
layer in the OSI Model and acts as an interface between end user software like a
web browser (or any other application that needs network communication) to
send or receive data over network. By offering support for multiple protocols like
SMTP, FTP, SNMP and DHCP the stack helps in effective communication of data.
Every one who is at network management and application development should
also have the idea about what are basic functions of Application Layer and
Protocols.
Frequently Asked Questions on Application Layer in OSI
Model – FAQ’s
What is the Function of the Application Layer?
The function of application layer is to provide an interface to send and receive data
from user.
Which is an Application Layer Service?
The application layer services are remote login, email services and file
transmission.
How does the Application Layer ensure data integrity?
It uses protocols and error-checking mechanisms to detect and correct
transmission errors.
Can the Application Layer handle multiple protocols simultaneously?
Yes, it supports concurrent protocols like HTTP, FTP, SMTP, and DNS for seamless
network operations.
How does the Application Layer interact with other OSI model layers?
It requests data formatting from the Presentation Layer and relies on lower layers
for connection and data transmission.
Protocol and Standard in Computer Networks
Last Updated : 13 Sep, 2024


Protocols and standards are important in computer networks. They are like the
rules and guidelines that allow different devices and systems to communicate and
work together smoothly. Protocols define how data is sent, received, and
processed, while standards ensure that various technologies are compatible with
each other. This coordination is critical for the Internet and other networks to
function constantly and efficiently.
Network protocol ensures that different technologies and components of the
network are compatible with one another, reliable, and able to function
together. In this article, we are going to discuss every point about protocols and
standards in computer networks.
What is Protocol?
A protocol is a set of rules that determines how data is sent and received over a
network. The protocol is just like a language that computers use to talk to each
other, ensuring they understand and can respond to each other’s messages
correctly. Protocols help make sure that data moves smoothly and securely
between devices on a network.
To make communication successful between devices, some rules and procedures
should be agreed upon at the sending and receiving ends of the system. Such rules
and procedures are called Protocols. Different types of protocols are used for
different types of communication.

Protocols
In the above diagrams, Protocols are shown as a set of rules. Communication
between the Sender and Receiver is not possible without Protocol.
Key Elements of Protocol
• Syntax: Syntax refers to the structure or the format of the data that gets
exchanged between the devices. Syntax of the message includes the type of
data, composition of the message, and sequencing of the message. The
starting 8 bits of data are considered as the address of the sender. The next 8
bits are considered to be the address of the receiver. The remaining bits are
considered as the message itself.
• Semantics: Semantics defines data transmitted between devices. It provides
rules and norms for understanding message or data element values and
actions.
• Timing: Timing refers to the synchronization and coordination between
devices while transferring the data. Timing ensures at what time data should
be sent and how fast data can be sent. For example, If a sender sends 100
Mbps but the receiver can only handle 1 Mbps, the receiver will overflow and
lose data. Timing ensures preventing of data loss, collisions, and other timing-
related issues.
• Sequence Control: Sequence control ensures the proper ordering of data
packets. The main responsibility of sequence control is to acknowledge the
data while it get received, and the retransmission of lost data. Through this
mechanism, the data is delivered in correct order.
• Flow Control: Flow control regulates device data delivery. It limits the
sender’s data or asks the receiver if it’s ready for more. Flow control prevents
data congestion and loss.
• Error Control: Error control mechanisms detect and fix data transmission
faults. They include error detection codes, data resend, and error recovery.
Error control detects and corrects noise, interference, and other problems to
maintain data integrity.
• Security : Network security protects data confidentiality, integrity, and
authenticity. which includes encryption, authentication, access control, and
other security procedures. Network communication’s privacy and
trustworthiness are protected by security standards.
Types of Protocol
• Network Layer Protocols : Network layer protocols operate in the network
layer which is also known as the Layer 3 of the network architecture.
Network layer protocols are responsible for packet routing, forwarding, and
addressing of data packets throughout the network. IP and ICMP are the
network layer protocols.
• Transport Layer Protocols: Transport layer protocols work in the transport
layer which provides end-to-end service ensuring data transfer across apps
on different devices. TCP and UDP are the most popular transport layer
protocols.
• Application Layer Protocol: Application layer protocol working in the
application layer of the network architecture provides communication
between applications running on different devices. The application layer
protocols enable cross-device communication. They format, exchange, and
interpret application data. HTTP, FTP, and SMTP are examples.
• Wireless Protocols: Wireless protocols basically used in wireless
communication which enables data transfer through wireless
networks. Bluetooth, Wi-Fi, and LTE protocols are examples.
• Routing Protocols: Routing protocol establishes the best/optimal network
pathways throughout the network for fastest data transmission. Routers
share information to develop and maintain routing tables. RIP, OSPF,
and BGP are examples.
• Security Protocols : security protocol protects data confidentiality, integrity,
and authenticity while transmission of data over the network. They
include SSL and TLS, encryption methods, and authentication protocols for
providing data security.
• Internet Protocols : IP identifies devices uniquely. Internet protocol
provides data communication through routing and forwarding data packets
from one device to another by unique addressing scheme.
Important Protocols Used in Computer Network
Here are some key protocols that are widely used in computer networks:
• TCP (Transmission Control Protocol): Ensures data is sent and received
accurately by breaking it into packets, sending them, and reassembling them
at the destination.
• IP (Internet Protocol): Addresses and routes the packets to make sure they
reach the right destination.
• HTTP/HTTPS (HyperText Transfer Protocol/Secure): HTTP used for
transferring web pages on the internet. When you browse a website, your
browser uses HTTP to request and display web pages. And HTTPs is a secure
version of HTTP that encrypts data to protect it from being intercepted.
• FTP (File Transfer Protocol): Used for transferring files between computers
on a network. It allows users to upload and download files.SMTP (Simple
Mail Transfer Protocol): Used for sending emails. It transfers emails from a
client to a server or between servers.
• DNS (Domain Name System): It is used to translates human-readable
domain names (like www.example.com) into IP addresses that computers use
to identify each other on the network.
• DHCP (Dynamic Host Configuration Protocol): Automatically assigns IP
addresses to devices on a network, ensuring each device has a unique
address.
• SSH (Secure Shell): Provides a secure way to access and manage devices
over a network. It encrypts the data, making it safe from eavesdropping.
• SNMP (Simple Network Management Protocol): Used for managing and
monitoring network devices like routers, switches, and servers. It collects and
organizes information about these devices
How are Protocols Used in Cyber Attacks?
Attackers can misuse the rules of how data is sent over the internet to cause
problems for systems. One common way they do this is through distributed denial-
of-service (DDoS) attacks.
For example, in a SYN flood attack, attackers exploit the TCP protocol. Normally, a
device sends a SYN packet to a server to start a connection, and the server
responds, expecting a final response to complete the connection. Attackers send
many SYN packets but never complete the connections. This overloads the server,
preventing it from working properly for real users.
Cloudflare offers solutions to stop these kinds of attacks. One of their services,
Cloudflare Magic Transit, protects against attacks targeting different levels of the
network system. In the case of a SYN flood attack, Cloudflare manages the TCP
connections for the server, so the server doesn’t get overwhelmed and can
continue to serve real users.
What is Standards?
Standards are the set of rules for data communication that are needed for the
exchange of information among devices. It is important to follow Standards which
are created by various Standard Organizations like IEEE, ISO, ANSI, etc.
Types of Standards
• De Facto Standard: The meaning of the word ” De Facto ” is ” By Fact ” or
“By Convention”. These are the standards that have not been approved by any
Organization but have been adopted as Standards because of their
widespread use. Also, sometimes these standards are often established by
Manufacturers.
For example : Apple and Google are two companies that established their
own rules for their products which are different. Also, they use some same
standard rules for manufacturing their products.
• De Jure Standard: The meaning of the word “De Jure” is “By Law” or
“By Regulations”.Thus, these are the standards that have been approved by
officially recognized bodies like ANSI, ISO, IEEE, etc. These are the standards
that are important to follow if it is required or needed.
For example : All the data communication standard protocols like SMTP,
TCP, IP, UDP etc. are important to follow the same when we need them.
Protocol and Standard Compliance in Network Security
• Interoperability: Protocols and standards allow devices and systems to
communicate. These protocols ensure network components can function
together, avoiding risks and security gaps produced by incompatible or
unsupported systems.
• Security Baseline : Protocols and standards contain security principles and
best practices that help secure network infrastructure. These protocols allow
organizations to protect sensitive data via encryption, authentication, and
access controls.
• Vulnerability Management : Network security protocols and standards help
organizations find and fix vulnerabilities. Many standards requires regular
security assessments, vulnerability scanning, and penetration testing to
discover network infrastructure flaws. Organizations can
prevent cyberattacks and address vulnerabilities by following these
compliance criteria.
Best Practices for Ensuring Protocol and Standard
Compliance
• Use cryptography tools to secure personal data transported across your
network, making sure that data encryption methods exceed industry
requirements.
• Perform frequent security checks on all network devices to discover
vulnerabilities and verify they fulfil compliance standards.
• Restrict user access to specified network zones to ensure secure data sharing
and prevent unauthorized access.
Conclusion
Protocols and standards enable secure and efficient
computer network communication. They regulate data exchange, formatting,
endpoints, and reliable device communication. These protocols and standards
ensure network security and performance. Compliance can prevent data breaches
and system breakdowns.
Frequently Asked Question on Protocol and Standards –
FAQs
What is the role of organizations like the IEEE and the IETF in protocol
development?
Organizations such as the IEEE and the IETF play important roles in defining and
maintaining networking protocols and standards. They provide platforms for
experts to cooperate, analyze suggestions, and reach agreements on new protocols
or changes to current ones.
Why are protocols and standards important in networking?
Protocols and standards ensure that devices from multiple companies may
communicate with one another effectively. They also contribute to consistent and
reliable data transfer, resulting in efficient networking operations.
What are some common networking protocols?
• TCP/IP
• FTP
• SMTP
• HTTP

How do protocols ensure data integrity and security?


Protocols usually include systems for error detection, correction, and encryption to
assure data integrity and security during transmission. TCP, for example, uses
sequence numbers and acknowledgment messages to ensure that data is delivered
reliably.

Examples of Data Link Layer Protocols


Last Updated : 05 Aug, 2020


Data Link Layer protocols are generally responsible to simply ensure and
confirm that the bits and bytes that are received are identical to the bits and
bytes being transferred. It is basically a set of specifications that are used for
implementation of data link layer just above the physical layer of the Open
System Interconnections (OSI) Model.
Some Common Data Link Protocols :
There are various data link protocols that are required for Wide Area
Network (WAN) and modem connections. Logical Link Control (LLC) is a
data link protocol of Local Area Network (LAN). Some of data link protocols
are given below :
1. Synchronous Data Link Protocol (SDLC) –
SDLC is basically a communication protocol of computer. It usually
supports multipoint links even error recovery or error correction also. It is
usually used to carry SNA (Systems Network Architecture) traffic and is
present precursor to HDLC. It is also designed and developed by IBM in
1975. It is also used to connect all of the remote devices to mainframe
computers at central locations may be in point-to-point (one-to-one) or
point-to-multipoint (one-to-many) connections. It is also used to make
sure that the data units should arrive correctly and with right flow from one
network point to next network point.

2. High-Level Data Link Protocol (HDLC) –


HDLC is basically a protocol that is now assumed to be an umbrella under
which many Wide Area protocols sit. It is also adopted as a part of X.25
network. It was originally created and developed by ISO in 1979. This
protocol is generally based on SDLC. It also provides best-effort
unreliable service and also reliable service. HDLC is a bit-oriented
protocol that is applicable for point-to-point and multipoint
communications both.

3. Serial Line Interface Protocol (SLIP) –


SLIP is generally an older protocol that is just used to add a framing byte
at end of IP packet. It is basically a data link control facility that is required
for transferring IP packets usually among Internet Service Providers (ISP)
and a home user over a dial-up link. It is an encapsulation of the TCP/IP
especially designed to work with over serial ports and several router
connections simply for communication. It is some limitations like it does
not provide mechanisms such as error correction or error detection.
4. Point to Point Protocol (PPP) –
PPP is a protocol that is basically used to provide same functionality as
SLIP. It is most robust protocol that is used to transport other types of
packets also along with IP Packets. It can also be required for dial-up and
leased router-router lines. It basically provides framing method to
describe frames. It is a character-oriented protocol that is also used for
error detection. It is also used to provides two protocols i.e. NCP and
LCP. LCP is used for bringing lines up, negotiation of options, bringing
them down whereas NCP is used for negotiating network-layer protocols.
It is required for same serial interfaces like that of HDLC.

5. Link Control Protocol (LCP) –


It was originally developed and created by IEEE 802.2. It is also used to
provide HDLC style services on LAN (Local Area Network). LCP is
basically a PPP protocol that is used for establishing, configuring, testing,
maintenance, and ending or terminating links for transmission of data
frames.

6. Link Access Procedure (LAP) –


LAP protocols are basically a data link layer protocols that are required for
framing and transferring data across point-to-point links. It also includes
some reliability service features. There are basically three types of LAP
i.e. LAPB (Link Access Procedure Balanced), LAPD (Link Access
Procedure D-Channel), and LAPF (Link Access Procedure Frame-Mode
Bearer Services). It is actually originated from IBM SDLC, which is being
submitted by IBM to the ISP simply for standardization.
7. Network Control Protocol (NCP) –
NCP was also an older protocol that was implemented by ARPANET. It
basically allows users to have access to use computers and some of the
devices at remote locations and also to transfer files among two or more
computers. It is generally a set of protocols that is forming a part of PPP.
NCP is always available for each and every higher-layer protocol that is
supported by PPP. NCP was replaced by TCP/IP in the 1980s.

TCP/IP Model
Last Updated : 05 Aug, 2024


The TCP/IP model is a fundamental framework for computer networking. It stands
for Transmission Control Protocol/Internet Protocol, which are the core protocols
of the Internet. This model defines how data is transmitted over networks,
ensuring reliable communication between devices. It consists of four layers: the
Link Layer, the Internet Layer, the Transport Layer, and the Application Layer.
Each layer has specific functions that help manage different aspects of network
communication, making it essential for understanding and working with modern
networks.
TCP/IP was designed and developed by the Department of Defense (DoD) in the
1960s and is based on standard protocols. The TCP/IP model is a concise version
of the OSI model. It contains four layers, unlike the seven layers in the OSI model.
In this article, we are going to discuss the TCP/IP model in detail.
TCP/IP model was developed alongside the creation of the ARPANET, which later
became the foundation of the modern internet. It was designed with a focus on the
practical aspects of networking at the time. The lower-level hardware details and
physical transmission medium were largely abstracted away in favor of higher-
level networking protocols.
What Does TCP/IP Do?
The main work of TCP/IP is to transfer the data of a computer from one device to
another. The main condition of this process is to make data reliable and accurate
so that the receiver will receive the same information which is sent by the sender.
To ensure that, each message reaches its final destination accurately, the TCP/IP
model divides its data into packets and combines them at the other end, which
helps in maintaining the accuracy of the data while transferring from one end to
another end. The TCP/IP model is used in the context of the real-world internet,
where a wide range of physical media and network technologies are in use. Rather
than specifying a particular Physical Layer, the TCP/IP model allows for flexibility
in adapting to different physical implementations.
Difference Between TCP and IP
TCP (Transmission
Feature Control Protocol) IP (Internet Protocol)

Ensures reliable, ordered, and Provides addressing and


Purpose error-checked delivery of data routing of packets across
between applications. networks.

Type Connection-oriented Connectionless

Manages data transmission Routes packets of data from


Function between devices, ensuring data the source to the destination
integrity and order. based on IP addresses.

No, IP itself does not handle


Yes, includes error checking
Error Handling errors; relies on upper-layer
and recovery mechanisms.
protocols like TCP.

Yes, includes flow control


Flow Control No
mechanisms.

Yes, manages network


Congestion Control No
congestion.

Breaks data into smaller


Breaks data into packets but
Data Segmentation packets and reassembles them
does not handle reassembly.
at the destination.

Header Size Larger, 20-60 bytes Smaller, typically 20 bytes

Does not guarantee delivery,


Reliability Provides reliable data transfer
reliability, or order.

Transmission Yes, acknowledges receipt of


No
Acknowledgment data packets.
How Does the TCP/IP Model Work?
Whenever we want to send something over the internet using the TCP/IP Model,
the TCP/IP Model divides the data into packets at the sender’s end and the same
packets have to be recombined at the receiver’s end to form the same data, and
this thing happens to maintain the accuracy of the data. TCP/IP model divides the
data into a 4-layer procedure, where the data first go into this layer in one order
and again in reverse order to get organized in the same way at the receiver’s end.
For more, you can refer to TCP/IP in Computer Networking.
Layers of TCP/IP Model
• Application Layer
• Transport Layer(TCP/UDP)
• Network/Internet Layer(IP)
• Network Access Layer
The diagrammatic comparison of the TCP/IP and OSI model is as follows:
TCP/IP and OSI

1. Network Access Layer


It is a group of applications requiring network communications. This layer is
responsible for generating the data and requesting connections. It acts on behalf
of the sender and the Network Access layer on the behalf of the receiver. During
this article, we will be talking on the behalf of the receiver.
The packet’s network protocol type, in this case, TCP/IP, is identified by network
access layer. Error prevention and “framing” are also provided by this layer. Point-
to-Point Protocol (PPP) framing and Ethernet IEEE 802.2 framing are two
examples of data-link layer protocols.
2. Internet or Network Layer
This layer parallels the functions of OSI’s Network layer. It defines the protocols
which are responsible for the logical transmission of data over the entire network.
The main protocols residing at this layer are as follows:
• IP: IP stands for Internet Protocol and it is responsible for delivering packets
from the source host to the destination host by looking at the IP addresses in
the packet headers. IP has 2 versions: IPv4 and IPv6. IPv4 is the one that most
websites are using currently. But IPv6 is growing as the number of IPv4
addresses is limited in number when compared to the number of users.
• ICMP: ICMP stands for Internet Control Message Protocol. It is encapsulated
within IP datagrams and is responsible for providing hosts with information
about network problems.
• ARP: ARP stands for Address Resolution Protocol. Its job is to find the
hardware address of a host from a known IP address. ARP has several types:
Reverse ARP, Proxy ARP, Gratuitous ARP, and Inverse ARP.
The Internet Layer is a layer in the Internet Protocol (IP) suite, which is the set of
protocols that define the Internet. The Internet Layer is responsible for routing
packets of data from one device to another across a network. It does this by
assigning each device a unique IP address, which is used to identify the device and
determine the route that packets should take to reach it.
Example: Imagine that you are using a computer to send an email to a friend.
When you click “send,” the email is broken down into smaller packets of data,
which are then sent to the Internet Layer for routing. The Internet Layer assigns
an IP address to each packet and uses routing tables to determine the best route
for the packet to take to reach its destination. The packet is then forwarded to the
next hop on its route until it reaches its destination. When all of the packets have
been delivered, your friend’s computer can reassemble them into the original
email message.
In this example, the Internet Layer plays a crucial role in delivering the email from
your computer to your friend’s computer. It uses IP addresses and routing tables
to determine the best route for the packets to take, and it ensures that the packets
are delivered to the correct destination. Without the Internet Layer, it would not
be possible to send data across the Internet.
3. Transport Layer
The TCP/IP transport layer protocols exchange data receipt acknowledgments
and retransmit missing packets to ensure that packets arrive in order and without
error. End-to-end communication is referred to as such. Transmission Control
Protocol (TCP) and User Datagram Protocol are transport layer protocols at this
level (UDP).
• TCP: Applications can interact with one another using TCP as though they
were physically connected by a circuit. TCP transmits data in a way that
resembles character-by-character transmission rather than separate packets.
A starting point that establishes the connection, the whole transmission in
byte order, and an ending point that closes the connection make up this
transmission.
• UDP: The datagram delivery service is provided by UDP, the other transport
layer protocol. Connections between receiving and sending hosts are not
verified by UDP. Applications that transport little amounts of data use UDP
rather than TCP because it eliminates the processes of establishing and
validating connections.
4. Application Layer
This layer is analogous to the transport layer of the OSI model. It is responsible for
end-to-end communication and error-free delivery of data. It shields the upper-
layer applications from the complexities of data. The three main protocols present
in this layer are:
• HTTP and HTTPS: HTTP stands for Hypertext transfer protocol. It is used by
the World Wide Web to manage communications between web browsers and
servers. HTTPS stands for HTTP-Secure. It is a combination of HTTP with
SSL(Secure Socket Layer). It is efficient in cases where the browser needs to
fill out forms, sign in, authenticate, and carry out bank transactions.
• SSH: SSH stands for Secure Shell. It is a terminal emulations software similar
to Telnet. The reason SSH is preferred is because of its ability to maintain the
encrypted connection. It sets up a secure session over a TCP/IP connection.
• NTP: NTP stands for Network Time Protocol. It is used to synchronize the
clocks on our computer to one standard time source. It is very useful in
situations like bank transactions. Assume the following situation without the
presence of NTP. Suppose you carry out a transaction, where your computer
reads the time at 2:30 PM while the server records it at 2:28 PM. The server
can crash very badly if it’s out of sync.
The host-to-host layer is a layer in the OSI (Open Systems Interconnection) model
that is responsible for providing communication between hosts (computers or
other devices) on a network. It is also known as the transport layer.
Some common use cases for the host-to-host layer include:
• Reliable Data Transfer: The host-to-host layer ensures that data is
transferred reliably between hosts by using techniques like error correction
and flow control. For example, if a packet of data is lost during transmission,
the host-to-host layer can request that the packet be retransmitted to ensure
that all data is received correctly.
• Segmentation and Reassembly: The host-to-host layer is responsible for
breaking up large blocks of data into smaller segments that can be
transmitted over the network, and then reassembling the data at the
destination. This allows data to be transmitted more efficiently and helps to
avoid overloading the network.
• Multiplexing and Demultiplexing: The host-to-host layer is responsible for
multiplexing data from multiple sources onto a single network connection,
and then demultiplexing the data at the destination. This allows multiple
devices to share the same network connection and helps to improve the
utilization of the network.
• End-to-End Communication: The host-to-host layer provides a connection-
oriented service that allows hosts to communicate with each other end-to-
end, without the need for intermediate devices to be involved in the
communication.
Example: Consider a network with two hosts, A and B. Host A wants to send a file
to host B. The host-to-host layer in host A will break the file into smaller segments,
add error correction and flow control information, and then transmit the segments
over the network to host B. The host-to-host layer in host B will receive the
segments, check for errors, and reassemble the file. Once the file has been
transferred successfully, the host-to-host layer in host B will acknowledge receipt
of the file to host A.
In this example, the host-to-host layer is responsible for providing a reliable
connection between host A and host B, breaking the file into smaller segments, and
reassembling the segments at the destination. It is also responsible for
multiplexing and demultiplexing the data and providing end-to-end
communication between the two hosts.
Why TCP/IP Model Does Not Have Physical Layer
The physical layer is not covered by the TCP/IP model because the data link layer
is considered the point at which the interface occurs between the TCP/IP stock
and the underlying network hardware. Also, it is designed to be independent of
the underlying physical media. This allows TCP/IP to be flexible and adaptable to
different types of physical connections, such as Ethernet, Wi-Fi, fiber optics, or
even older technologies like dial-up modems. The physical layer is typically
handled by hardware components and standards specific to the physical medium
being used, like Ethernet cables or radio waves for Wi-Fi.
Other Common Internet Protocols
TCP/IP Model covers many Internet Protocols. The main rule of these Internet
Protocols is how the data is validated and sent over the Internet. Some Common
Internet Protocols include:
• HTTP (Hypertext Transfer Protocol): HTTP takes care of Web Browsers
and Websites.
• FTP (File Transfer Protocol): FTP takes care of how the file is to be sent
over the Internet.
• SMTP (Simple Mail Transfer Protocol): SMTP is used to send and receive
data.
Difference between TCP/IP and OSI Model
TCP/IP OSI

OSI refers to Open Systems


TCP refers to Transmission Control Protocol.
Interconnection.

TCP/IP uses both the session and presentation OSI uses different session and
layer in the application layer itself. presentation layers.

TCP/IP follows connectionless a horizontal


OSI follows a vertical approach.
approach.

The Transport layer in TCP/IP does not In the OSI model, the transport layer
provide assurance delivery of packets. provides assurance delivery of packets.

While in the OSI model, Protocols are


Protocols cannot be replaced easily in TCP/IP
better covered and are easy to replace with
model.
the technology change.

TCP/IP model network layer only provides Connectionless and connection-oriented


connectionless (IP) services. The transport services are provided by the network layer
layer (TCP) provides connections. in the OSI model.
Advantages of TCP/IP Model
• Interoperability: The TCP/IP model allows different types of computers and
networks to communicate with each other, promoting compatibility and
cooperation among diverse systems.
• Scalability: TCP/IP is highly scalable, making it suitable for both small and
large networks, from local area networks (LANs) to wide area networks
(WANs) like the internet.
• Standardization: It is based on open standards and protocols, ensuring that
different devices and software can work together without compatibility
issues.
• Flexibility: The model supports various routing protocols, data types, and
communication methods, making it adaptable to different networking needs.
• Reliability: TCP/IP includes error-checking and retransmission features that
ensure reliable data transfer, even over long distances and through various
network conditions.
Disadvantages of TCP/IP Model
• Complex Configuration: Setting up and managing a TCP/IP network can be
complex, especially for large networks with many devices. This complexity
can lead to configuration errors.
• Security Concerns: TCP/IP was not originally designed with security in mind.
While there are now many security protocols available (such as SSL/TLS),
they have been added on top of the basic TCP/IP model, which can lead to
vulnerabilities.
• Inefficiency for Small Networks: For very small networks, the overhead and
complexity of the TCP/IP model may be unnecessary and inefficient
compared to simpler networking protocols.
• Limited by Address Space: Although IPv6 addresses this issue, the older
IPv4 system has a limited address space, which can lead to issues with
address exhaustion in larger networks.
• Data Overhead: TCP, the transport protocol, includes a significant amount of
overhead to ensure reliable transmission. This can reduce efficiency,
especially for small data packets or in networks where speed is crucial.
Conclusion
In conclusion, the TCP/IP model is the backbone of modern internet
communication, allowing different devices and networks to connect and share
information reliably. Despite some complexity and security concerns, its
flexibility, scalability, and widespread adoption make it essential for both small
and large networks. Overall, the TCP/IP model is crucial for ensuring efficient and
effective network communication.
Frequently Asked Questions on TCP/IP Model – FAQs
Which IP Addresses Do TCP/IP Work With?
TCP/IP generally works with both the IP that is, IPv4 and IPv6. If you are using IPv4
or IPv6, it seems that you are already working on TCP/IP Model.
How many layers are in the TCP/IP Model?
The TCP/IP Model has four layers:
• Network Interface Layer
• Internet Layer
• Transport Layer
• Application Layer

What does each layer do?


• Network Interface Layer: Handles the physical transmission of data over a
network.
• Internet Layer: Manages the routing of data packets across the network.
• Transport Layer: Ensures reliable data transmission between devices.
• Application Layer: Provides protocols for specific data communication services
on a process-to-process level.
How is the TCP/IP Model different from the OSI Model?
The OSI Model has seven layers, while the TCP/IP Model has four layers. The TCP/IP
Model is simpler and more practical, making it more widely used in real-world
networking.
What are the main protocols in the TCP/IP Model?
Key protocols include:
• TCP (Transmission Control Protocol): Ensures reliable data transmission.
• IP (Internet Protocol): Handles addressing and routing of data packets.
• HTTP/HTTPS: Used for web communication.
• FTP: Used for file transfers.
• SMTP: Used for email communication.

What is the role of IP addresses in the TCP/IP Model?


IP addresses identify devices on a network, enabling data to be routed to the
correct destination.

User Datagram Protocol (UDP)


Last Updated : 27 Sep, 2024


User Datagram Protocol (UDP) is a Transport Layer protocol. UDP is a part of
the Internet Protocol suite, referred to as UDP/IP suite. Unlike TCP, it is
an unreliable and connectionless protocol. So, there is no need to establish a
connection before data transfer. The UDP helps to establish low-latency and loss-
tolerating connections over the network. The UDP enables process-to-process
communication.
What is User Datagram Protocol?
User Datagram Protocol (UDP) is one of the core protocols of the Internet Protocol
(IP) suite. It is a communication protocol used across the internet for time-
sensitive transmissions such as video playback or DNS lookups . Unlike
Transmission Control Protocol (TCP), UDP is connectionless and does not
guarantee delivery, order, or error checking, making it a lightweight and efficient
option for certain types of data transmission.

UDP Header
UDP header is an 8-byte fixed and simple header, while for TCP it may vary from
20 bytes to 60 bytes. The first 8 Bytes contain all necessary header information
and the remaining part consists of data. UDP port number fields are each 16 bits
long, therefore the range for port numbers is defined from 0 to 65535; port
number 0 is reserved. Port numbers help to distinguish different user requests or
processes.
UDP Header

• Source Port: Source Port is a 2 Byte long field used to identify the port
number of the source.
• Destination Port: It is a 2 Byte long field, used to identify the port of the
destined packet.
• Length: Length is the length of UDP including the header and the data. It is a
16-bits field.
• Checksum: Checksum is 2 Bytes long field. It is the 16-bit one’s complement
of the one’s complement sum of the UDP header, the pseudo-header of
information from the IP header, and the data, padded with zero octets at the
end (if necessary) to make a multiple of two octets.
Notes – Unlike TCP, the Checksum calculation is not mandatory in UDP. No Error
control or flow control is provided by UDP. Hence UDP depends on IP and ICMP
for error reporting. Also UDP provides port numbers so that is can differentiate
between users requests.
Applications of UDP
• Used for simple request-response communication when the size of data is less
and hence there is lesser concern about flow and error control.
• It is a suitable protocol for multicasting as UDP supports packet switching.
• UDP is used for some routing update protocols like RIP(Routing Information
Protocol).
• Normally used for real-time applications which can not tolerate uneven
delays between sections of a received message.
• VoIP (Voice over Internet Protocol) services, such as Skype and WhatsApp,
use UDP for real-time voice communication. The delay in voice
communication can be noticeable if packets are delayed due to congestion
control, so UDP is used to ensure fast and efficient data transmission.
• DNS (Domain Name System) also uses UDP for its query/response messages.
DNS queries are typically small and require a quick response time, making
UDP a suitable protocol for this application.
• DHCP (Dynamic Host Configuration Protocol) uses UDP to dynamically assign
IP addresses to devices on a network. DHCP messages are typically small, and
the delay caused by packet loss or retransmission is generally not critical for
this application.
• Following implementations uses UDP as a transport layer protocol:
o NTP (Network Time Protocol)
o DNS (Domain Name Service)
o BOOTP, DHCP.
o NNP (Network News Protocol)
o Quote of the day protocol
o TFTP, RTSP, RIP.
• The application layer can do some of the tasks through UDP-
o Trace Route
o Record Route
o Timestamp
• UDP takes a datagram from Network Layer , attaches its header, and sends it
to the user. So, it works fast.
TCP vs UDP
Transmission Control Protocol User Datagram
Basis (TCP) Protocol (UDP)

UDP is the Datagram-


oriented protocol. This is
TCP is a connection-oriented protocol. because there is no
Connection orientation means that the overhead for opening a
communicating devices should establish connection, maintaining a
a connection before transmitting data connection, or terminating
and should close the connection after a connection. UDP is
transmitting the data. efficient for broadcast and
multicast types of network
Type of Service transmission.

TCP is reliable as it guarantees the The delivery of data to the


delivery of data to the destination destination cannot be
Reliability router. guaranteed in UDP.
Transmission Control Protocol User Datagram
Basis (TCP) Protocol (UDP)

TCP provides extensive error-checking


UDP has only the basic
mechanisms. It is because it provides
Error checking error-checking mechanism
flow control and acknowledgment of
using checksums.
mechanism data.

Acknowledgme An acknowledgment segment is No acknowledgment


nt present. segment.

There is no sequencing of
Sequencing of data is a feature of
data in UDP. If the order is
Transmission Control Protocol (TCP).
required, it has to be
this means that packets arrive in order
managed by the
at the receiver.
Sequence application layer.

UDP is faster, simpler, and


TCP is comparatively slower than UDP.
Speed more efficient than TCP.

There is no retransmission
Retransmission of lost packets is
of lost packets in the User
possible in TCP, but not in UDP.
Retransmission Datagram Protocol (UDP).

TCP has a (20-60) bytes variable length UDP has an 8 bytes fixed-
Header Length header. length header.

Weight TCP is heavy-weight. UDP is lightweight.

Handshaking Uses handshakes such as SYN, ACK, It’s a connectionless


Techniques SYN-ACK protocol i.e. No handshake

UDP supports
TCP doesn’t support Broadcasting.
Broadcasting Broadcasting.

TCP is used by HTTP, UDP is used


Protocols HTTPs , FTP , SMTP and Telnet . by DNS, DHCP,
Transmission Control Protocol User Datagram
Basis (TCP) Protocol (UDP)

TFTP, SNMP , RIP,


and VoIP.

UDP connection is a
The TCP connection is a byte stream.
Stream Type message stream.

Overhead Low but higher than UDP. Very low.

This protocol is used in


situations where quick
This protocol is primarily utilized in
communication is
situations when a safe and trustworthy
necessary but where
communication procedure is necessary,
dependability is not a
such as in email, on the web surfing,
concern, such as VoIP,
and in military services.
game streaming, video,
Applications and music streaming, etc.

Advantages of UDP
• Speed: UDP is faster than TCP because it does not have the overhead of
establishing a connection and ensuring reliable data delivery.
• Lower latency: Since there is no connection establishment, there is lower
latency and faster response time.
• Simplicity: UDP has a simpler protocol design than TCP, making it easier to
implement and manage.
• Broadcast support: UDP supports broadcasting to multiple recipients,
making it useful for applications such as video streaming and online gaming.
• Smaller packet size: UDP uses smaller packet sizes than TCP, which can
reduce network congestion and improve overall network performance.
• User Datagram Protocol (UDP) is more efficient in terms of both latency and
bandwidth.
Disadvantages of UDP
• No reliability: UDP does not guarantee delivery of packets or order of
delivery, which can lead to missing or duplicate data.
• No congestion control: UDP does not have congestion control, which means
that it can send packets at a rate that can cause network congestion.
• Vulnerable to attacks: UDP is vulnerable to denial-of-service attacks , where
an attacker can flood a network with UDP packets, overwhelming the network
and causing it to crash.
• Limited use cases: UDP is not suitable for applications that require reliable
data delivery, such as email or file transfers, and is better suited for
applications that can tolerate some data loss, such as video streaming or
online gaming.
How is UDP used in DDoS attacks?
A UDP flood attack is a type of Distributed Denial of Service (DDoS) attack
where an attacker sends a large number of User Datagram Protocol
(UDP) packets to a target port.
• UDP Protocol : Unlike TCP, UDP is connectionless and doesn’t require a
handshake before data transfer. When a UDP packet arrives at a server, it
checks the specified port for listening applications. If no app is found, the
server sends an ICMP “destination unreachable” packet to the supposed
sender (usually a random bystander due to spoofed IP addresses).
• Attack Process :
o The attacker sends UDP packets with spoofed IP sender addresses to
random ports on the target system.
o The server checks each incoming packet’s port for a listening
application (usually not found due to random port selection).
o The server sends ICMP “destination unreachable” packets to the
spoofed sender (random bystanders).
o The attacker floods the victim with UDP data packets, overwhelming
its resources.
• Mitigation : To protect against UDP flood attacks, monitoring network traffic
for sudden spikes and implementing security measures are crucial.
Organizations often use specialized tools and services to detect and mitigate
such attacks effectively.
UDP Pseudo Header
• The purpose of using a pseudo-header is to verify that the UDP packet has
reached its correct destination
• The correct destination consist of a specific machine and a specific protocol
port number within that machine
UDP pseudo header

UDP Pseudo Header Details


• The UDP header itself specify only protocol port number.thus , to verify the
destination UDP on the sending machine computes a checksum that covers
the destination IP address as well as the UDP packet.
• At the ultimate destination, UDP software verifies the checksum using the
destination IP address obtained from the header of the IP packet that carried
the UDP message.
• If the checksum agrees, then it must be true that the packet has reached the
intended destination host as well as the correct protocol port within that host.
User Interface
A user interface should allow the creation of new receive ports, receive operations
on the receive ports that returns the data octets and an indication of source port
and source address, and an operation that allows a datagram to be sent, specifying
the data, source and destination ports and address to be sent.
IP Interface
• The UDP module must be able to determine the source and destination
internet address and the protocol field from internet header
• One possible UDP/IP interface would return the whole internet datagram
including the entire internet header in response to a receive operation
• Such an interface would also allow the UDP to pass a full internet datagram
complete with header to the IP to send. the IP would verify certain fields for
consistency and compute the internet header checksum.
• The IP interface allows the UDP module to interact with the network layer of
the protocol stack, which is responsible for routing and delivering data across
the network.
• The IP interface provides a mechanism for the UDP module to communicate
with other hosts on the network by providing access to the underlying IP
protocol.
• The IP interface can be used by the UDP module to send and receive data
packets over the network, with the help of IP routing and addressing
mechanisms.
GATE Questions for Practice
• GATE CS 2013, Question 12
• GATE CS 2012, Question 65
• GATE CS 2007, Question 20
• GATE CS 2005, Question 23
• GATE IT 2008, Question 66
• GATE Mock 2015, Question 5
Conclusion
The User Datagram Protocol (UDP) is an important Transport Layer protocol in
the Internet Protocol (IP) suite, identified for its speed and efficiency due to its
connectionless and lightweight design. While UDP lacks TCP’s stability and error-
checking features, it used in applications that need low latency and real-time
performance, such as streaming, online gaming, and DNS lookups. Its simplicity
and support for broadcast and multicast broadcasts make it a useful tool for
specialized applications, despite its vulnerability to data loss and network
congestion.
Frequently Asked Questions on UDP – FAQs
Name the protocols that uses UDP?
The protocol that uses UDP Model are:
• Domain Name System(DNS)
• Simple Network Management Protocol(SMTP)
• Routing Information Protocol(RIP)

Which is faster: TCP or UDP?


UDP is faster than TCP.
Is UDP secure?
Yes UDP provide various security mechanism.
Is UDP a layer 3 or 4?
UDP is layer 4 protocol of OSI Model

Difference Between IPv4 and IPv6


Last Updated : 30 Aug, 2024


The address through which any computer communicates with our computer is
simply called an Internet Protocol Address or IP address. For example, if we want
to load a web page or download something, we require the address to deliver that
particular file or webpage. That address is called an IP Address.
There are two versions of IP: IPv4 and IPv6. IPv4 is the older version, while IPv6
is the newer one. Both have their own features and functions, but they differ in
many ways. Understanding these differences helps us see why we need IPv6 as the
internet grows and evolves.
What is IP?
An IP, or Internet Protocol address, is a unique set of numbers assigned to each
device connected to a network, like the Internet. It’s like an address for your
computer, phone, or any other device, allowing them to communicate with each
other. When you visit a website, your device uses the IP address to find and
connect to the website’s server.
Types of IP Addresses
• IPv4 (Internet Protocol Version 4)
• IPv6 (Internet Protocol Version 6)
What is IPv4?
IPv4 addresses consist of two things: the network address and the host address. It
stands for Internet Protocol version four. It was introduced in 1981 by
DARPA and was the first deployed version in 1982 for production on SATNET and
on the ARPANET in January 1983.
IPv4 addresses are 32-bit integers that have to be expressed in Decimal Notation.
It is represented by 4 numbers separated by dots in the range of 0-255, which have
to be converted to 0 and 1, to be understood by Computers. For Example, An IPv4
Address can be written as 189.123.123.90.
IPv4 Address Format
IPv4 Address Format is a 32-bit Address that comprises binary digits separated by
a dot (.).

IPv4 Address Format


Drawback of IPv4
• Limited Address Space : IPv4 has a limited number of addresses, which is
not enough for the growing number of devices connecting to the internet.
• Complex Configuration : IPv4 often requires manual configuration or DHCP
to assign addresses, which can be time-consuming and prone to errors.
• Less Efficient Routing : The IPv4 header is more complex, which can slow
down data processing and routing.
• Security Issues : IPv4 does not have built-in security features, making it more
vulnerable to attacks unless extra security measures are added.
• Limited Support for Quality of Service (QoS) : IPv4 has limited capabilities
for prioritizing certain types of data, which can affect the performance of real-
time applications like video streaming and VoIP.
• Fragmentation : IPv4 allows routers to fragment packets, which can lead to
inefficiencies and increased chances of data being lost or corrupted.
• Broadcasting Overhead : IPv4 uses broadcasting to communicate with
multiple devices on a network, which can create unnecessary network traffic
and reduce performance.
What is IPv6?
IPv6 is based on IPv4 and stands for Internet Protocol version 6. It was first
introduced in December 1995 by Internet Engineering Task Force. IP version 6 is
the new version of Internet Protocol, which is way better than IP version 4 in terms
of complexity and efficiency. IPv6 is written as a group of 8 hexadecimal numbers
separated by colon (:). It can be written as 128 bits of 0s and 1s.
IPv6 Address Format
IPv6 Address Format is a 128-bit IP Address, which is written in a group of 8
hexadecimal numbers separated by colon (:).

IPv6 Address Format

To switch from IPv4 to IPv6, there are several strategies:


• Dual Stacking : Devices can use both IPv4 and IPv6 at the same time. This
way, they can talk to networks and devices using either version.
• Tunneling : This method allows IPv6 users to send data through an IPv4
network to reach other IPv6 users. Think of it as creating a “tunnel” for IPv6
traffic through the older IPv4 system.
• Network Address Translation (NAT) : NAT helps devices using different
versions of IP addresses (IPv4 and IPv6) to communicate with each other by
translating the addresses so they understand each other.
Difference Between IPv4 and IPv6
IPv4 IPv6

IPv4 has a 32-bit address length IPv6 has a 128-bit address length

It Supports Manual It supports Auto and renumbering address


and DHCP address configuration configuration

In IPv4 end to end, connection In IPv6 end-to-end, connection integrity is


integrity is Unachievable Achievable

It can generate 4.29×10 9 address The address space of IPv6 is quite large it can
space produce 3.4×10 38 address space

The Security feature is dependent IPSEC is an inbuilt security feature in the IPv6
on the application protocol

Address representation of IPv4 is


Address representation of IPv6 is in hexadecimal
in decimal

Fragmentation performed by In IPv6 fragmentation is performed only by the


Sender and forwarding routers sender

In IPv4 Packet flow identification In IPv6 packet flow identification are Available and
is not available uses the flow label field in the header

In IPv4 checksum field is available In IPv6 checksum field is not available

It has a broadcast Message In IPv6 multicast and anycast message transmission


Transmission Scheme scheme is available
IPv4 IPv6

In IPv4 Encryption and


Authentication facility not In IPv6 Encryption and Authentication are provided
provided

IPv4 has a header of 20-60 bytes. IPv6 has a header of 40 bytes fixed

IPv4 can be converted to IPv6 Not all IPv6 can be converted to IPv4

IPv4 consists of 4 fields which are IPv6 consists of 8 fields, which are separated by a
separated by addresses dot (.) colon (:)

IPv4’s IP addresses are divided


into five different classes. Class A
IPv6 does not have any classes of the IP address.
, Class B, Class C, Class D , Class
E.

IPv4 supports VLSM( Variable


IPv6 does not support VLSM.
Length subnet mask ).

Example of IPv6:
Example of IPv4: 66.94.29.13
2001:0000:3238:DFE1:0063:0000:0000:FEFB

Benefits of IPv6 over IPv4


The recent Version of IP IPv6 has a greater advantage over IPv4. Here are some of
the mentioned benefits:
• Larger Address Space: IPv6 has a greater address space than IPv4, which is
required for expanding the IP Connected Devices. IPv6 has 128 bit IP Address
rather and IPv4 has a 32-bit Address.
• Improved Security: IPv6 has some improved security which is built in with
it. IPv6 offers security like Data Authentication, Data Encryption, etc. Here, an
Internet Connection is more Secure.
• Simplified Header Format: As compared to IPv4, IPv6 has a simpler and
more effective header Structure, which is more cost-effective and also
increases the speed of Internet Connection.
• Prioritize: IPv6 contains stronger and more reliable support for QoS features,
which helps in increasing traffic over websites and increases audio and video
quality on pages.
• Improved Support for Mobile Devices: IPv6 has increased and better
support for Mobile Devices. It helps in making quick connections over other
Mobile Devices and in a safer way than IPv4.
Conclusion
In simple terms, IPv4 and IPv6 are two versions of Internet Protocol addresses
used to identify devices on a network. IPv6 is the newer version and offers many
improvements over IPv4, such as a much larger address space, better security, and
more efficient routing . However, IPv4 is still widely used, and the transition to
IPv6 is ongoing. The main difference is that IPv6 can handle many more devices,
which is crucial as the number of internet-connected devices continues to grow.
Frequently Asked Questions on Differences between
IPv4 and IPv6 – FAQs
Which is Better IPv4 or IPv6?
IPv6 is better than IPv4 as IPv6 is more advanced and has more features than IPv4.
Can we use both IPv4 and IPv6
Yes, We can use both IPv4 and IPV6 in a single machine. There are devices that
support dual addressing. When two devices communicate, they agree on which IP
Version to use.
Which is faster IPv4 or IPv6?
Generally, IPv6 is faster than IPv4. However, when we go to a larger packet size, IPv6
can be slow in some cases.

Difference Between Connection-oriented and


Connection-less Services
Last Updated : 03 Oct, 2024


Two basic forms of networking communication are connection-oriented and
connection-less services. In order to provide dependable communication,
connection-oriented services create a dedicated connection before transferring
data. On the other hand, connection-less services prioritize speed and efficiency
over reliability by transmitting data without establishing a connection. These
types of services are offered by the network layer.
What is a Connection-Oriented Service?
Connection-oriented service is related to the telephone system. It includes
connection establishment and connection termination. In a connection-oriented
service, the Handshake method is used to establish the connection between sender
and receiver. Before data transmission starts, connection-oriented services create
a dedicated communication channel between the sender and the recipient. As the
connection is kept open until all data is successfully transferred, this guarantees
dependable data delivery. One example is TCP (Transmission Control Protocol),
which ensures error-free and accurate data packet delivery.

What is Connection-Less Service?


Connection-less service is related to the postal system. It does not include any
connection establishment and connection termination. Connection-less Service
does not give a guarantee of reliability. In this, Packets do not follow the same path
to reach their destination. Connection-less Services deliver individual data
packets without first making a connection. Since each packet is sent separately,
delivery, order, and mistake correction cannot be guaranteed. As a result, the
service is quicker but less dependable. UDP (User Datagram Protocol) is one
example, which is frequently used for streaming where dependability is not as
important as speed.

Difference Between Connection-oriented and


Connection-less Services
Connection-oriented Service Connection-less Service

Connection-oriented service is related to the Connection-less service is related to the


telephone system. postal system.

Connection-oriented service is preferred by Connection-less Service is preferred by


long and steady communication. bursty communication.

Connection-less Service is not


Connection-oriented Service is necessary.
compulsory.

Connection-oriented Service is feasible. Connection-less Service is not feasible.

In connection-oriented Service, Congestion is In connection-less Service, Congestion


not possible. is possible.

Connection-oriented Service gives the Connection-less Service does not give a


guarantee of reliability. guarantee of reliability.

In connection-oriented Service, Packets In connection-less Service, Packets do


follow the same route. not follow the same route.
Connection-oriented Service Connection-less Service

Connection-oriented services require a Connection-less Service requires a


bandwidth of a high range. bandwidth of low range.

Ex: TCP (Transmission Control Protocol) Ex: UDP (User Datagram Protocol)

Connection-less Service does not


Connection-oriented requires authentication.
require authentication.

Conclusion
Depending on the particular requirements of the application, connection-oriented
or connection-less services might be chosen. While connection-less services offer
faster and more flexible communication, they are better suited for real-time
applications where speed is crucial. Connection-oriented services, on the other
hand, offer reliability and ordered delivery, making them excellent for critical data
transfer.
Difference Between Connection-oriented and
Connection-less Services – FAQs
What benefits do connection-oriented services offer?
They guarantee that data arrives intact and in order by offering dependable data
transfer, error detection, and correction.
When is a connection-less service used?
When speed and efficiency are more important than dependability, use a
connection-less service (e.g., VoIP (Voice over IP), live streaming, online gaming).
What kinds of services are connection-oriented?
Examples include the Transmission Control Protocol (TCP), which establishes and
maintains a connection during the exchange of messages.

Socket Programming in Java


Last Updated : 17 Jan, 2023


This article describes a very basic one-way Client and Server setup where a Client
connects, sends messages to the server and the server shows them using a socket
connection. There’s a lot of low-level stuff that needs to happen for these things to
work but the Java API networking package (java.net) takes care of all of that,
making network programming very easy for programmers.
Client-Side Programming
Establish a Socket Connection
To connect to another machine we need a socket connection. A socket connection
means the two machines have information about each other’s network location
(IP Address) and TCP port. The java.net.Socket class represents a Socket. To open
a socket:
Socket socket = new Socket(“127.0.0.1”, 5000)
• The first argument – IP address of Server. ( 127.0.0.1 is the IP address of
localhost, where code will run on the single stand-alone machine).
• The second argument – TCP Port. (Just a number representing which
application to run on a server. For example, HTTP runs on port 80. Port
number can be from 0 to 65535)
Communication
To communicate over a socket connection, streams are used to both input and
output the data.
Closing the connection
The socket connection is closed explicitly once the message to the server is sent.
In the program, the Client keeps reading input from a user and sends it to the
server until “Over” is typed.
Java Implementation
• Java

// A Java program for a Client

import java.io.*;

import java.net.*;

public class Client {


// initialize socket and input output streams

private Socket socket = null;

private DataInputStream input = null;

private DataOutputStream out = null;

// constructor to put ip address and port

public Client(String address, int port)

// establish a connection

try {

socket = new Socket(address, port);

System.out.println("Connected");

// takes input from terminal

input = new DataInputStream(System.in);

// sends output to the socket

out = new DataOutputStream(

socket.getOutputStream());

}
catch (UnknownHostException u) {

System.out.println(u);

return;

catch (IOException i) {

System.out.println(i);

return;

// string to read message from input

String line = "";

// keep reading until "Over" is input

while (!line.equals("Over")) {

try {

line = input.readLine();

out.writeUTF(line);

catch (IOException i) {

System.out.println(i);
}

// close the connection

try {

input.close();

out.close();

socket.close();

catch (IOException i) {

System.out.println(i);

public static void main(String args[])

Client client = new Client("127.0.0.1", 5000);

Server Programming
Establish a Socket Connection
To write a server application two sockets are needed.
• A ServerSocket which waits for the client requests (when a client makes a
new Socket())
• A plain old Socket to use for communication with the client.
Communication
getOutputStream() method is used to send the output through the socket.
Close the Connection
After finishing, it is important to close the connection by closing the socket as
well as input/output streams.
• Java

// A Java program for a Server

import java.net.*;

import java.io.*;

public class Server

//initialize socket and input stream

private Socket socket = null;

private ServerSocket server = null;

private DataInputStream in = null;

// constructor with port

public Server(int port)

{
// starts server and waits for a connection

try

server = new ServerSocket(port);

System.out.println("Server started");

System.out.println("Waiting for a client ...");

socket = server.accept();

System.out.println("Client accepted");

// takes input from the client socket

in = new DataInputStream(

new BufferedInputStream(socket.getInputStream()));

String line = "";

// reads message from client until "Over" is sent

while (!line.equals("Over"))

{
try

line = in.readUTF();

System.out.println(line);

catch(IOException i)

System.out.println(i);

System.out.println("Closing connection");

// close connection

socket.close();

in.close();

catch(IOException i)

System.out.println(i);
}

public static void main(String args[])

Server server = new Server(5000);

Important Points
• Server application makes a ServerSocket on a specific port which is 5000. This
starts our Server listening for client requests coming in for port 5000.
• Then Server makes a new Socket to communicate with the client.
socket = server.accept()
• The accept() method blocks(just sits there) until a client connects to the server.
• Then we take input from the socket using getInputStream() method. Our Server
keeps receiving messages until the Client sends “Over”.
• After we’re done we close the connection by closing the socket and the input
stream.
• To run the Client and Server application on your machine, compile both of
them. Then first run the server application and then run the Client application.
To run on Terminal or Command Prompt
Open two windows one for Server and another for Client
1. First run the Server application as,
$ java Server
Server started
Waiting for a client …
2. Then run the Client application on another terminal as,
$ java Client
It will show – Connected and the server accepts the client and shows,
Client accepted
3. Then you can start typing messages in the Client window. Here is a sample
input to the Client
Hello
I made my first socket connection
Over
Which the Server simultaneously receives and shows,
Hello
I made my first socket connection
Over
Closing connection
Notice that sending “Over” closes the connection between the Client and the
Server just like said before.
If you’re using Eclipse or likes of such-
1. Compile both of them on two different terminals or tabs
2. Run the Server program first
3. Then run the Client program
4. Type messages in the Client Window which will be received and shown by the
Server Window simultaneously.
5. Type Over to end.

java.net.ServerSocket Class in Java


Last Updated : 20 Dec, 2022


ServerSocket Class is used for providing system-independent
implementation of the server-side of a client/server Socket Connection. The
constructor for ServerSocket throws an exception if it can’t listen on the
specified port (for example, the port is already being used).
It is widely used so the applications of java.net.ServerSocket class which is
as follows:
1. In java.nio channel, ServerSocket class is used for retrieving a
serverSocket associated with this channel.
2. In java.rmi.Server, ServerSocket class is used to create a server socket
on the specified port (port 0 indicates an anonymous port).
3. In javax.net, Server socket is used widely so as to:
• return an unbound server socket.
• return a server socket bound to the specified port.
• return a server socket bound to the specified port, and uses the
specified connection backlog.
• return a server socket bound to the specified port, with a specified
listen backlog and local IP.
Let us do go through the methods of this class which is as follows:

Method Description

Listens for a connection to be made to this


accept()
socket and accepts it.

Binds the ServerSocket to a specific address


bind(SocketAddress endpoint)
(IP address and port number).

Binds the ServerSocket to a specific address


(IP address and port number) and requests
bind(SocketAddress endpoint, int
queqe length. If a request arrives when the
backlog)
queue is full then the request will be rejected
by the server.

close() Closes this socket

Returns the unique ServerSocketChannel


getChannel()
object associated with this socket, if any.

Returns the local address of this server


getInetAddress()
socket.

Returns the port number on which this


getLocalPort()
socket is listening.
Method Description

Returns the address of the endpoint this


getLocalSocketAddress() socket is bound to, or null if it is not bound
yet.

Gets the value of the SO_RCVBUF option


for this ServerSocket, that is the proposed
getReceiveBufferSize()
buffer size that will be used for Sockets
accepted from this ServerSocket.

getReuseAddress() Tests if SO_REUSEADDR is enabled.

getSoTimeout() Retrieve setting for SO_TIMEOUT.

Subclasses of ServerSocket use this method


implAccept(Socket s) to override accept() to return their own
subclass of the socket.

Returns the binding state of the


isBound()
ServerSocket.

isClosed() Returns the closed state of the ServerSocket.

setPerformancePreferences(int
Sets performance preferences for this
connectionTime, int latency, int
ServerSocket
bandwidth)

Sets a default proposed value for the


Sets performance preferences for this
SO_RCVBUF option for sockets accepted
ServerSocket
from this ServerSocket.

Enable/disable the SO_REUSEADDR


setReuseAddress(boolean on)
socket option.

Sets the server socket implementation


setSocketFactory(SocketImplFactory fac)
factory for the application.
Method Description

Enable/disable SO_TIMEOUT with the


setSoTimeout(int timeout)
specified timeout, in milliseconds.

Returns the implementation address and


toString() implementation port of this socket as a
String.

implementation:
Example 1 Server-Side
• Java

// Java Program to implement ServerSocket class

// Server Side

// Importing required libraries

import java.io.*;

import java.net.*;

// Main class

public class MyServer {

// Main driver method

public static void main(String[] args)


{

// Try block to check for exceptions

try {

// Creating an object of ServerSocket class

// in the main() method for socket connection

ServerSocket ss = new ServerSocket(6666);

// Establishing a connection

Socket soc = ss.accept();

// Invoking input stream via getInputStream()

// method by creating DataInputStream class

// object

DataInputStream dis

= new DataInputStream(soc.getInputStream());

String str = (String)dis.readUTF();


// Display the string on the console

System.out.println("message= " + str);

// Lastly close the socket using standard close

// method to release memory resources

ss.close();

// Catch block to handle the exceptions

catch (Exception e) {

// Display the exception on the console

System.out.println(e);

Output:

URL Class in Java with Examples


Last Updated : 18 Apr, 2022


URL known as Uniform Resource Locator is simply a string of text that identifies
all the resources on the Internet, telling us the address of the resource, how to
communicate with it, and retrieve something from it.

Components of a URL
A URL can have many forms. The most general however follows a three-
components system as proposed below:
1. Protocol: HTTP is the protocol here
2. Hostname: Name of the machine on which the resource lives.
3. File Name: The pathname to the file on the machine.
4. Port Number: Port number to which to connect (typically optional).

URL Class

The URL class is the gateway to any of the resources available on the internet. A
Class URL represents a Uniform Resource Locator, which is a pointer to a
“resource” on the World Wide Web. A resource can point to a simple file or
directory, or it can refer to a more complicated object, such as a query to a
database or to a search engine.

Constructors of the URL class

1. URL(String address) throws MalformedURLException: It creates a URL


object from the specified String.
2. URL(String protocol, String host, String file): Creates a URL object from the
specified protocol, host, and file name.
3. URL(String protocol, String host, int port, String file): Creates a URL object
from protocol, host, port, and file name.
4. URL(URL context, String spec): Creates a URL object by parsing the given
spec in the given context.
5. URL(String protocol, String host, int port, String file, URLStreamHandler
handler):
Creates a URL object from the specified protocol, host, port number, file, and
handler.
6. URL(URL context, String spec, URLStreamHandler handler):
Creates a URL by parsing the given spec with the specified handler within a
specified context.

Important Methods used in URL class

Method Action Performed

getAuthority() Returns the authority part of URL or null if empty

getDefaultPort() Returns the default port used

getFile() Returns the file name.

getHost() Return the hostname of the URL in IPv6 format

getPath() Returns the path of the URL, or null if empty

getPort() Returns the port associated with the protocol specified by the URL

getProtocol() Returns the protocol used by the URL

the Returns the query part of URL. A query is a part after the ‘?’ in the
getQuery() URL. Whenever logic is used to display the result, there would be a
query field in the URL. It is similar to querying a database.

Returns the reference of the URL object. Usually, the reference is the
getRef() part marked by a ‘#’ in the URL. You can see the working example by
querying anything on Google and seeing the part after ‘#’

As in any class, toString() returns the string representation of the given


toString()
URL object.

Example:
• Java

// Java program to demonstrate working of URL

// Importing required classes

import java.net.MalformedURLException;

import java.net.URL;

// Main class

// URL class

public class GFG {

// Main driver method

public static void main(String[] args)

throws MalformedURLException

// Creating a URL with string representation

URL url1 = new URL(

"https://www.google.co.in/?gfe_rd=cr&ei=ptYq"
+ "WK26I4fT8gfth6CACg#q=geeks+for+geeks+java");

// Creating a URL with a protocol,hostname,and path

URL url2 = new URL("http", "www.geeksforgeeks.org",

"/jvm-works-jvm-architecture/");

URL url3 = new URL(

"https://www.google.co.in/search?"

+ "q=gnu&rlz=1C1CHZL_enIN71"

+ "4IN715&oq=gnu&aqs=chrome..69i57j6"

+ "9i60l5.653j0j7&sourceid=chrome&ie=UTF"

+ "-8#q=geeks+for+geeks+java");

// Printing the string representation of the URL

System.out.println(url1.toString());

System.out.println(url2.toString());

System.out.println();

System.out.println(

"Different components of the URL3-");


// Retrieving the protocol for the URL

System.out.println("Protocol:- "

+ url3.getProtocol());

// Retrieving the hostname of the url

System.out.println("Hostname:- " + url3.getHost());

// Retrieving the default port

System.out.println("Default port:- "

+ url3.getDefaultPort());

// Retrieving the query part of URL

System.out.println("Query:- " + url3.getQuery());

// Retrieving the path of URL

System.out.println("Path:- " + url3.getPath());

// Retrieving the file name

System.out.println("File:- " + url3.getFile());


// Retrieving the reference

System.out.println("Reference:- " + url3.getRef());

Output:
https://www.google.co.in/?gfe_rd=cr&ei=ptYqWK26I4fT8gfth6CACg#q=geeks+
for+geeks+java
https://www.geeksforgeeks.org/jvm-works-jvm-architecture/

Different components of the URL3-


Protocol:- https
Hostname:- www.google.co.in
Default port:- 443
Query:-
q=gnu&rlz=1C1CHZL_enIN714IN715&oq=gnu&aqs=chrome..69i57j69i60l5.653j0j
7&sourceid=chrome&ie=UTF-8
Path:- /search
File:-
/search?q=gnu&rlz=1C1CHZL_enIN714IN715&oq=gnu&aqs=chrome..69i57j69i60l
5.653j0j7&sourceid=chrome&ie=UTF-8
Reference:- q=geeks+for+geeks+java

You might also like