Notes Unit-I Application Layer
Notes Unit-I Application Layer
Unit I
APPLICATION LAYER
Syllabus: Client Server Paradigm: Communication using TCP and UDP, Peer to Peer Paradigm,
Application Layer Protocols: DNS, FTP, TFTP, HTTP, SMTP, POP, IMAP, MIME, DHCP,
TELNET.
Introduction:
The Application Layer is 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.
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.
Client-server paradigm:
The traditional paradigm is called the client-server paradigm. In this paradigm, the service
provider is an application program, called the server process; it runs continuously, waiting for
another application program, called the client process, to make a connection through the Internet
and ask for service. Normally few server processes are available that can provide a specific type
of service, but there are many clients that request service from any of these server processes. The
server process must be running all the time; the client process is started when the client needs to
receive service. For example, a telephone directory center in any area can be a server; a
subscriber that calls and asks for a specific telephone number can be thought of as a client. The
directory center must be ready and available all the time; the subscriber can call the center for a
short period when the service is needed.
Peer-to-Peer paradigm:
In this paradigm, there is no need for a server process to be running all the time and waiting for
the client processes to connect. The responsibility is shared between peers. A computer
connected to the Internet can provide service at one time and receive service at another time. A
computer can even provide and receive services at the same time. Figure shows an example of
communication in this paradigm.
Communication by phone is a peer-to-peer activity; no party needs to wait for the other party to
call. The peer-to-peer paradigm can be used in a situation, when some computers connected to
the Internet have something to share with each other. For example, if an Internet user has a file
available to share with other Internet users, there is no need for the file holder to become a server
and run a server process all the time waiting for other users to connect and to get the file.
Client-Server Programming:
In a client-server paradigm, communication at the application layer is between two running
application programs called processes: a client and a server. A client is a running program that
initializes the communication by sending a request; a server is another application program that
waits for a request from a client. The server handles the request received from a client, prepares a
result, and sends the result back to the client. The lifetime of a server is infinite: it should be
started and run forever, waiting for the clients. The lifetime of a client is finite. It sends a finite
number of requests to the corresponding server, receives the responses, and stops.
In application layer, communication between a client process and a server process is the
communication between two sockets. As far as the application layer is concerned,
communication between a client process and a server process is communication between two
sockets, created at two ends, as shown in Figure.
The client thinks that the socket is the entity that receives the request and gives the response; the
server thinks that the socket is the one that has a request and needs the response. If we create two
sockets, one at each end, and define the source and destination addresses correctly, we can use
the available instructions to send and receive data. The rest is the responsibility of the operating
system and the embedded TCP/IP protocol.
Socket Addresses:
The interaction between a client and a server is two-way communication. In a two-way
communication, we need a pair of addresses: local (sender) and remote (receiver). The local
address in one direction is the remote address in the other direction and vice versa.Since
communication in the client-server paradigm is between two sockets, we need a pair of socket
addresses for communication: a local socket address and a remote socket address.A socket
address should first define the computer on which a client or a server is running. A computer in
the Internet is defined by its IP address. a socket address should be a combination of an IP
address and a port number as shown in Figure.
Types of Socket:
1) A stream socket uses TCP for connection-oriented communication. It is also called a TCP
socket.
2) A datagram socket uses UDP for connectionless communication. It is also called a UDP
socket.
3) A raw socket uses IP directly. It is used in such applications as ICMP and OSPF.
Socket Primitives
1. Socket creation:
int sockfd = socket(domain, type, protocol)
sockfd: socket descriptor, an integer (like a file-handle)
domain: integer, specifies communication domain. We use AF_ LOCAL as defined in the
POSIX standard for communication between processes on the same host. For
communicating between processes on different hosts connected by IPV4, we use AF_INET
and AF_I NET 6 for processes connected by IPV6.
type: communication type
SOCK_STREAM: TCP(reliable, connection oriented)
SOCK_DGRAM: UDP(unreliable, connectionless)
protocol: Protocol value for Internet Protocol(IP), which is 0. This is the same number
which appears on protocol field in the IP header of a packet.(man protocols for more
details)
2. Setsockopt:
This helps in manipulating options for the socket referred by the file descriptor sockfd. This is
completely optional, but it helps in reuse of address and port. Prevents error such as: “address
already in use”.
int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
3. Bind:
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
After the creation of the socket, the bind function binds the socket to the address and port
number specified in addr(custom data structure). In the example code, we bind the server to the
localhost, hence we use INADDR_ANY to specify the IP address.
4. Listen:
int listen(int sockfd, int backlog);
It puts the server socket in a passive mode, where it waits for the client to approach the server
to make a connection. The backlog, defines the maximum length to which the queue of
pending connections for sockfd may grow. If a connection request arrives when the queue is
full, the client may receive an error with an indication of ECONNREFUSED.
5. Accept:
int new_socket= accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
It extracts the first connection request on the queue of pending connections for the listening
socket, sockfd, creates a new connected socket, and returns a new file descriptor referring to
that socket. At this point, the connection is established between client and server, and they are
ready to transfer data.
Generic Domains
o It defines the registered hosts according to their generic behavior.
o Each node in a tree defines the domain name, which is an index to the DNS database.
o It uses three-character labels, and these labels describe the organization type.
Label Description
aero Airlines and aerospace companies
biz Businesses or firms
com Commercial Organizations
coop Cooperative business Organizations
edu Educational institutions
gov Government institutions
info Information service providers
int International Organizations
mil Military groups
museum Museum & other nonprofit organizations
name Personal names
net Network Support centers
org Nonprofit Organizations
pro Professional individual Organizations
Country Domain:
The format of country domain is same as a generic domain, but it uses two-character country
abbreviations (e.g., us for the United States) in place of three character organizational
abbreviations.
Inverse Domain:
The inverse domain is used for mapping an address to a name. When the server has received a
request from the client, and the server contains the files of only authorized clients. To determine
whether the client is on the authorized list or not, it sends a query to the DNS server and ask for
mapping an address to the name.
Working of DNS:
o DNS is a client/server network communication protocol. DNS clients send requests to
the. server while DNS servers send responses to the client.
o Client requests contain a name which is converted into an IP address known as a forward
DNS lookups while requests containing an IP address which is converted into a name
known as reverse DNS lookups.
o DNS implements a distributed database to store the name of all the hosts available on the
internet.
o If a client like a web browser sends a request containing a hostname, then a piece of
software such as DNS resolver sends a request to the DNS server to obtain the IP address
of a hostname. If DNS server does not contain the IP address associated with a hostname,
then it forwards the request to another DNS server. If IP address has arrived at the
resolver, which in turn completes the request over the internet protocol.
FTP and TFTP are application layer protocols that aid in transferring files from a server to a
client and from a client to a server. FTP is far more complicated than TFTP. There are some
important distinctions between FTP and TFTP. TFTP uses a single connection when transferring
files between the client and the server, whereas FTP uses two connections. The connections
utilized in FTP are TCP ports 20 and 21 for the control connection. In contrast, the TFTP makes
use of UDP port 69.
What is FTP?
o FTP stands for File transfer protocol.
o FTP is a standard internet protocol provided by TCP/IP used for transmitting the files
from one host to another.
o It is mainly used for transferring the web page files from their creator to the computer
that acts as a server for other computers on the internet.
o It is also used for downloading the files to computer from other servers.
Objectives of FTP
o It provides the sharing of files.
o It is used to encourage the use of remote computers.
o It transfers the data more reliably and efficiently.
Why FTP?
Although transferring files from one system to another is very simple and straightforward, but
sometimes it can cause problems. For example, two systems may have different file conventions.
Two systems may have different ways to represent text and data. Two systems may have
different directory structures. FTP protocol overcomes these problems by establishing two
connections between hosts. One connection is used for data transfer, and another connection is
used for the control connection.
Mechanism of FTP
The above figure shows the basic model of the FTP. The FTP client has three components: the
user interface, control process, and data transfer process. The server has two components: the
server control process and the server data transfer process.
o Control Connection: The control connection uses very simple rules for communication.
Through control connection, we can transfer a line of command or line of response at a
time. The control connection is made between the control processes. The control
connection remains connected during the entire interactive FTP session.
o Data Connection: The Data Connection uses very complex rules as data types may vary.
The data connection is made between data transfer processes. The data connection opens
when a command comes for transferring the files and closes when the file is transferred.
FTP Clients:
o FTP client is a program that implements a file transfer protocol which allows you to
transfer files between two hosts on the internet.
o It allows a user to connect to a remote host and upload or download the files.
o It has a set of commands that we can use to connect to a host, transfer the files between
you and your host and close the connection.
o The FTP program is also available as a built-in component in a Web browser. This GUI
based FTP client makes the file transfer very easy and also does not require to remember
the FTP commands.
Advantages of FTP:
o Speed: One of the biggest advantages of FTP is speed. The FTP is one of the fastest way
to transfer the files from one computer to another computer.
o Efficient: It is more efficient as we do not need to complete all the operations to get the
entire file.
o Security: To access the FTP server, we need to login with the username and password.
Therefore, we can say that FTP is more secure.
o Back & forth movement: FTP allows us to transfer the files back and forth. Suppose
you are a manager of the company, you send some information to all the employees, and
they all send information back on the same server.
Disadvantages of FTP:
o The standard requirement of the industry is that all the FTP transmissions should be
encrypted. However, not all the FTP providers are equal and not all the providers offer
encryption. So, we will have to look out for the FTP providers that provides encryption.
o FTP serves two operations, i.e., to send and receive large files on a network. However,
the size limit of the file is 2GB that can be sent. It also doesn't allow you to run
simultaneous transfers to multiple receivers.
o Passwords and file contents are sent in clear text that allows unwanted eavesdropping.
So, it is quite possible that attackers can carry out the brute force attack by trying to guess
the FTP password.
o It is not compatible with every system.
What is TFTP?
TFTP is an abbreviation for "Trivial File Transfer Protocol". It is a sample protocol that is
commonly used for file transmission. TFTP employs the User Datagram Protocol (UDP) to
transport data from one end to the other. In comparison to the FTP, it is very simple in design
and has limited functionalities (FTP). TFTP doesn't provide authentication or security while
transferring data. As a result, boot data or configuration files are typically shared between
computer systems in a local setup. It aids in booting devices and systems that lack storage
devices or hard disk drives because utilizing a small amount of memory may be easily installed.
It is primarily used for booting systems that store configuration on a remote TFTP server. It
operates on Port number 69, and its service is given by UDP.
Advantages of TFTP
1. It utilizes the User Datagram Protocol (UDP) protocol.
2. It is very easy to use and implement.
3. It needs minimum coding.
4. It needs minimum memory utilization.
5. It is a faster file transfer protocol.
Disadvantages
1. It doesn't offer file security as compared to FTP.
2. It doesn't list the directory's contents.
3. It is an unsecured FTP.
4. There is no encryption or authentication mechanism.
o When a user logs into a local computer, then it is known as local login.
o When the workstation running terminal emulator, the keystrokes entered by the user are
accepted by the terminal driver. The terminal driver then passes these characters to the
operating system which in turn, invokes the desired application program.
o However, the operating system has special meaning to special characters. For example,
in UNIX some combination of characters have special meanings such as control
character with "z" means suspend. Such situations do not create any problem as the
terminal driver knows the meaning of such characters. But, it can cause the problems in
remote login.
Remote login
o When the user wants to access an application program on a remote computer, then the
user must perform remote login.
o The network virtual terminal is an interface that defines how data and commands are sent
across the network.
o In today's world, systems are heterogeneous. For example, the operating system accepts a
special combination of characters such as end-of-file token running a DOS operating
system ctrl+z while the token running a UNIX operating system is ctrl+d.
o TELNET solves this issue by defining a universal interface known as network virtual
interface.
o The TELNET client translates the characters that come from the local terminal into NVT
form and then delivers them to the network. The Telnet server then translates the data
from NVT form into a form which can be understandable by a remote computer.
o First, we will break the SMTP client and SMTP server into two components such as user
agent (UA) and mail transfer agent (MTA). The user agent (UA) prepares the message,
creates the envelope and then puts the message in the envelope. The mail transfer agent
(MTA) transfers this mail across the internet.
o SMTP allows a more complex system by adding a relaying system. Instead of just having
one MTA at sending side and one at receiving side, more MTAs can be added, acting
either as a client or server to relay the email.
o The relaying system without TCP/IP protocol can also be used to send the emails to
users, and this is achieved by the use of the mail gateway. The mail gateway is a relay
MTA that can be used to receive an email.
Working of SMTP
1. Composition of Mail: A user sends an e-mail by composing an electronic mail message
using a Mail User Agent (MUA). Mail User Agent is a program which is used to send
and receive mail. The message contains two parts: body and header. The body is the main
part of the message while the header includes information such as the sender and
recipient address. The header also includes descriptive information such as the subject of
the message. In this case, the message body is like a letter and header is like an envelope
that contains the recipient's address.
2. Submission of Mail: After composing an email, the mail client then submits the
completed e-mail to the SMTP server by using SMTP on TCP port 25.
3. Delivery of Mail: E-mail addresses contain two parts: username of the recipient and
domain name. For example, vivek@gmail.com, where "vivek" is the username of the
recipient and "gmail.com" is the domain name.
If the domain name of the recipient's email address is different from the sender's domain
name, then MSA will send the mail to the Mail Transfer Agent (MTA). To relay the
email, the MTA will find the target domain. It checks the MX record from Domain Name
System to obtain the target domain. The MX record contains the domain name and IP
address of the recipient's domain. Once the record is located, MTA connects to the
exchange server to relay the message.
4. Receipt and Processing of Mail: Once the incoming message is received, the exchange
server delivers it to the incoming server (Mail Delivery Agent) which stores the e-mail
where it waits for the user to retrieve it.
5. Access and Retrieval of Mail: The stored email in MDA can be retrieved by using
MUA (Mail User Agent). MUA can be accessed by using login and password.
Suppose sender wants to send the mail to receiver. First mail is transmitted to the sender's mail
server. Then, the mail is transmitted from the sender's mail server to the receiver's mail server
over the internet. On receiving the mail at the receiver's mail server, the mail is then sent to the
user. The whole process is done with the help of Email protocols. The transmission of mail from
the sender to the sender's mail server and then to the receiver's mail server is done with the help
of the SMTP protocol. At the receiver's mail server, the POP or IMAP protocol takes the data
and transmits to the actual user.
What is POP3?
The POP3 is a simple protocol and having very limited functionalities. In the case of the POP3
protocol, the POP3 client is installed on the recipient system while the POP3 server is installed
on the recipient's mail server.
To establish the connection between the POP3 server and the POP3 client, the POP3 server asks
for the user name to the POP3 client. If the username is found in the POP3 server, then it sends
the ok message. It then asks for the password from the POP3 client; then the POP3 client sends
the password to the POP3 server. If the password is matched, then the POP3 server sends the OK
message, and the connection gets established. After the establishment of a connection, the client
can see the list of mails on the POP3 mail server. In the list of mails, the user will get the email
numbers and sizes from the server. Out of this list, the user can start the retrieval of mail.
Once the client retrieves all the emails from the server, all the emails from the server are deleted.
Therefore, we can say that the emails are restricted to a particular machine, so it would not be
possible to access the same mails on another machine. This situation can be overcome by
configuring the email settings to leave a copy of mail on the mail server.
The IMAP protocol resides on the TCP/IP transport layer which means that it implicitly uses the
reliability of the protocol. Once the TCP connection is established between the IMAP client and
IMAP server, the IMAP server listens to the port 143 by default, but this port number can also be
changed.
than on the local server. The POP3 also faces another issue, i.e., data security and safety. The
solution to this problem is to use the disconnected access model, which provides the benefits of
both online and offline access. In the disconnected access model, the user can retrieve the mail
for local use as in the POP3 protocol, and the user does not need to be connected to the internet
continuously. However, the changes made to the mailboxes are synchronized between the client
and the server. The mail remains on the server so different applications in the future can access
it. When developers recognized these benefits, they made some attempts to implement the
disconnected access model. This is implemented by using the POP3 commands that provide the
option to leave the mails on the server. This works, but only to a limited extent, for example,
keeping track of which messages are new or old become an issue when both are retrieved and
left on the server. So, the POP3 lacks some features which are required for the proper
disconnected access model.
IMAP Features
IMAP was designed for a specific purpose that provides a more flexible way of how the user
accesses the mailbox. It can operate in any of the three modes, i.e., online, offline, and
disconnected mode. Out of these, offline and disconnected modes are of interest to most users of
the protocol.
The following are the features of an IMAP protocol:
o Access and retrieve mail from remote server: The user can access the mail from the
remote server while retaining the mails in the remote server.
o Set message flags: The message flag is set so that the user can keep track of which
message he has already seen.
o Manage multiple mailboxes: The user can manage multiple mailboxes and transfer
messages from one mailbox to another. The user can organize them into various
categories for those who are working on various projects.
o Determine information prior to downloading: It decides whether to retrieve or not before
downloading the mail from the mail server.
o Downloads a portion of a message: It allows you to download the portion of a message,
such as one body part from the mime-multi part. This can be useful when there are large
multimedia files in a short-text element of a message.
o Organize mails on the server: In case of POP3, the user is not allowed to manage the
mails on the server. On the other hand, the users can organize the mails on the server
according to their requirements like they can create, delete or rename the mailbox on the
server.
o Search: Users can search for the contents of the emails.
o Check email-header: Users can also check the email-header prior to downloading.
o Create hierarchy: Users can also create the folders to organize the mails in a hierarchy.
1. The IMAP is a client-server protocol like POP3 and most other TCP/IP application
protocols. The IMAP4 protocol functions only when the IMAP4 must reside on the server
where the user mailboxes are located. In c the POP3 does not necessarily require the
same physical server that provides the SMTP services. Therefore, in the case of the
IMAP protocol, the mailbox must be accessible to both SMTP for incoming mails and
IMAP for retrieval and modifications.
2. The IMAP uses the Transmission Control Protocol (TCP) for communication to ensure
the delivery of data and also received in the order.
3. The IMAP4 listens on a well-known port, i.e., port number 143, for an incoming
connection request from the IMAP4 client.
1. MIME Version
It defines the version of the MIME protocol. This header usually has a parameter value 1.0,
indicating that the message is formatted using MIME.
2. Content Type
It describes the type and subtype of information to be sent in the message. These messages can
be of many types such as Text, Image, Audio, Video, and they also have many subtypes such
that the subtype of the image can be png or jpeg. Similarly, the subtype of Video can be WEBM,
MP4 etc.
3. Content Type Encoding
In this field, it is told which method has been used to convert mail information into ASCII or
Binary number, such as 7-bit encoding, 8-bit encoding, etc.
4. Content Id
In this field, a unique "Content Id" number is appended to all email messages so that they can be
uniquely identified.
5. Content description
This field contains a brief description of the content within the email. This means that
information about whatever is being sent in the mail is clearly in the "Content Description". This
field also provides the information of name, creation date, and modification date of the file.
Example of Content description
Content-Description: attachment; filename = javatpoint.jpeg;
modification-date = "Wed, 12 Feb 1997 16:29:51 -0500";
Features of HTTP:
o Connectionless protocol: HTTP is a connectionless protocol. HTTP client initiates a
request and waits for a response from the server. When the server receives the request,
the server processes the request and sends back the response to the HTTP client after
which the client disconnects the connection.
o Media independent: HTTP protocol is a media independent as data can be sent as long
as both the client and server know how to handle the data content. It is required for both
the client and server to specify the content type in MIME-type header.
o Stateless: HTTP is a stateless protocol as both the client and server know each other only
during the current request. Due to this nature of the protocol, both the client and server do
not retain the information between various requests of the web pages.
HTTP Transactions:
The above figure shows the HTTP transaction between client and server. The client initiates a
transaction by sending a request message to the server. The server replies to the request message
by sending a response message.
Messages
HTTP messages are of two types: request and response. Both the message types follow the same
message format.
Request Message: The request message is sent by the client that consists of a request line,
headers, and sometimes a body.
Response Message: The response message is sent by the server to the client that consists of a
status line, headers, and sometimes a body.
o Method: The method is the protocol used to retrieve the document from a server. For
example, HTTP.
o Host: The host is the computer where the information is stored, and the computer is
given an alias name. Web pages are mainly stored in the computers and the computers are
given an alias name that begins with the characters "www". This field is not mandatory.
o Port: The URL can also contain the port number of the server, but it's an optional field. If
the port number is included, then it must come between the host and path and it should be
separated from the host by a colon.
o Path: Path is the pathname of the file where the information is stored. The path itself
contain slashes that separate the directories from the subdirectories and files.
o Subnet: Subnet is the partitioned segments of the IP networks. Subnet is used to keep
networks manageable.
o Lease: Lease is the length of time for which a DHCP client holds the IP address
information. When a lease expires, the client has to renew it.
o DHCP relay: A host or router that listens for client messages being broadcast on that
network and then forwards them to a configured server. The server then sends responses
back to the relay agent that passes them along to the client. DHCP relay can be used to
centralize DHCP servers instead of having a server on each subnet.
Benefits of DHCP
There are following benefits of DHCP:
Centralized administration of IP configuration: DHCP IP configuration information can be
stored in a single location and enables that administrator to centrally manage all IP address
configuration information.
Dynamic host configuration: DHCP automates the host configuration process and eliminates
the need to manually configure individual host. When TCP/IP (Transmission control
protocol/Internet protocol) is first deployed or when IP infrastructure changes are required.
Seamless IP host configuration: The use of DHCP ensures that DHCP clients get accurate and
timely IP configuration IP configuration parameter such as IP address, subnet mask, default
gateway, IP address of DND server and so on without user intervention.
Flexibility and scalability: Using DHCP gives the administrator increased flexibility, allowing
the administrator to move easily change IP configuration when the infrastructure changes.