Unit - 6 (Application Layer)
Unit - 6 (Application Layer)
By
• Remote Login
There are several applications in the application layer of the Internet model that follow the
client/server paradigm. The client/server programs can be divided into two categories: those
that can be directly used by the user, such as e-mail, and those that support other
application programs. The Domain Name System (DNS) is a supporting program that is used
by other programs such as e-mail. Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
Application Layer I Domain Name Server (DNS)
A system that can map a name to an address or an address to a name.
When the Internet was small, mapping was done using a host file.
Every host could store the host file on its disk and update it periodically
from a master host file. When a program or a user wanted to map a name
to an address, the host consulted the host file and found the mapping.
The names of machine should be unique. A name space that maps each address to a unique name
can be organized in two ways:
• Flat Name Space
A name is assigned to an address. A name in this space is a sequence of characters without structure.
Disadvantage: It cannot be used in a large system such as the Internet because it must be
centrally controlled to avoid any ambiguity and duplication.
The names are unique without the need for assignment by a central authority. The central authority
controls only part of the name, not the whole.
DNS | Domain Name Space Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
The information contained in the domain name space must be stored. However, it is very inefficient
and also not reliable to have just one computer store such a huge amount of information.
• If a server divides its domain into sub-domains and delegates part of its authority to other servers,
“domain” and “zone” refer to different things. The information about the nodes in the sub-domains
is stored in the servers at the lower levels, with the original server keeping some sort of reference to
there lower-level servers.
A ROOT SERVER is a server whose zone consists of the whole tree. A root server usually does not
store any information about domains but delegates it authority to other servers, keeping references
to those servers.
There are several root servers, each covering the whole domain name space. The servers are
distributed all around the world.
In the Internet, the domain name space is divided into three different sections:
Country Domains – Follows same format as the generic domains but uses two-character country
abbreviations in place of three-character organizational abbreviation at the first level.
in – India
us – United States of America
au – Australia
fr – France
DNS | Domain Name Space Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
The response message consists of a HEADER, Question Records, Answer Records, Authoritative
Records, and Additional records.
DNS | Message Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
Header (12-bytes length) Both query and response messages have the same header format with some
fields set to zero for the query messages.
Identification (16 bits): Used by client to match the response with the query.
• The client uses a different identification number each time it sends a query.
• The server duplicates this number in the corresponding response.
Flags (16 bits): The flags subfield is a collection of subfields that define the type of the message, the type of
answer requested, the type of desired resolution (recursive or iterative), and so on.
The number of question records sub-field contains the number of queries in the question section of the message.
The number of answer records subfield contains the number of answer records in the answer section of the response
message. Its value is zero in the query message.
DNS | Encapsulation Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
In both cases the well-know port used by the server is port 53.
UDP connection is used when the size of the response message is less than 512 bytes
because most UDP packages have a 512-byte packet size limit.
If the size of the response message is more than 512 bytes, a TCP connection is used.
• If the resolver has prior knowledge that the size of the response message is more than 512 bytes,
it uses the TCP connection.
• If the resolver does not know the size of the response message, it can use the UDP connection.
However, if the size of the response message is more than 512 bytes, the server truncates
the message and turns on the TC bit. The resolver now opens a TCP connection and
REPEATS THE REQUEST to get the full response from the server.
Application Layer Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
The TCP/IP protocol that supports email on the Internet is called Simple Mail Transfer Protocol
(SMTP).
SMTP Supports:
• Sending a single message to one or more recipients.
• Sending messages that include text, voice, video or graphics.
• Sending messages to users on networks outside the Internet.
This is accomplished through the use of a Mail Gateway, which is a relay MTA that can receive mail
prepared by a protocol other than SMTP and transform it to SMTP format before sending it.
It can also receive mail in SMTP format and change it to another format before sending it.
SMTP | Architecture Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
Scenario I:
When the sender and the receiver of an email are on the same mail server, we need only two
UAs.
SMTP | Architecture Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
Scenario II:
When the sender and the receiver of an email are on different mail servers, we need two UAs and
a pair of MTAs (Client and Server).
SMTP | Architecture Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
Scenario III:
When the sender is connected to the mail server via a LAN or a WAN, we need two UAs and
two pairs of MTAs (Client and Server)
SMTP | Architecture Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
Scenario IV:
When both sender and receiver are connected to the mail server via a LAN or a WAN, we need
two UAs, two pairs of MTAs, and a pair of Message Access Agents (MAAs).
SMTP | User Agent Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
The scenario works well if the server runs on a computer that has a permanent Internet connection.
Two protocols exist that allow a remote user to retrieve mail from a permanent mailbox and allows
user to manipulate the mailbox content:
Post Office Protocol (POP)
Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
Internet Message Access Protocol (IMAP)
SMTP | Message Access Agent (MAA) Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
IMAP works by keeping mail on the server. POP works by downloading your mail to your computer.
Like POP, IMAP also defines an abstraction known as a mailbox; mailbox are located on the same
computer as a server.
Like POP, a user runs an IMAP client that contacts the server to retrieve messages.
Unlike POP, IMAP allows a user to dynamically create, delete, or rename mailboxes.
IMAP also provides extended functionality for message retrieval and processing. A user can obtain
information about a message or examine header fields without retrieving the entire message.
A user can search for a specified string and retrieve specified portions of a message.
Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
POP3
SMTP | Addresses Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
To deliver mail, a mail handling system must use an addressing system with unique addresses.
The address consists of two parts: a Local Part and a Domain Name, separated by an @ sign.
SMTP | Commands and Responses
SMTP uses COMMANDS and RESPONSES to transfer messages between an MTA clients and an
MTA server.
Commands:
The format of a command consists of a keyword followed by zero or more argument.
Keyword: Argument(s)
Responses:
2nd and 3rd Digit provide further details about the response.
SMTP | Mail Transfer Phases Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
Connection Establishment
After a client has made a TCP connection to the well known port 25, the SMTP server starts the
connection phase.
SMTP | Mail Transfer Phases
Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
Mail Transfer
SMTP | Mail Transfer Phases Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
Connection Termination
After the connection termination phase, the TCP connection must be closed.
Electronic Mail: mail servers
user
agent
user
Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad) agent
Electronic Mail: SMTP [RFC 2821]
• uses TCP to reliably transfer email message from client to server,
port 25
• direct transfer: sending server to receiving server
• three phases of transfer
• handshaking (greeting)
• transfer of messages
• closure
• command/response interaction
• commands: ASCII text
• response: status code and phrase
• messages must be in 7-bit ASCII
1 mail
mail
server user
user server
2 agent
agent 3 6
4 5
• Cookies ??
Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
Application Layer I Hypertext Transfer Protocol (HTTP)
World Wide Web (WWW) is a distributed client server service in which a client using a browser can
access a service using a server.
HTTP protocol is used for communication between a browser and a web server or between
intermediate machines and web servers.
Web Documents:
• Static Documents
• Dynamic Documents
• Active Documents Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
HTTP | Transaction Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
HTTP itself is a stateless protocol. It uses the services of TCP (Port 80).
Request Line: Defines the Request Type, Resource (URL) and HTTP Version.
• GET: Used when a client wants to retrieve a document from the server.
The address of the document is defined in the URL.
The server usually responds with the contents of the document in the body of the response
message.
HTTP | Transaction
• HEAD: Used when a client wants some information about the document but
not the document itself.
• POST: Used when a client provides some information for the server.
• DELETE: Used to remove a document on the server. Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
HTTP | Transaction
The URL defines four things: Method, Host Computer, Port and Path.
The method is the protocol used to retrieve the document. Like HTTP, FTP, TELNET etc.
The host computer where the information is located. Web pages are usually stored in computers, and
computers are given alias names that usually begin with the character “www”.
Version:
The version of HTTP.
The header exchanges additional information between the client and the
server.
The header can be one or more header lines.
Each header line is made of: Header Name, Colon, Space, Header Value.
Request Headers:
Specifies the client’s configuration and the client’s preferred document format.
• Accept: Shows the media format the client can accept.
• Accept-charset: Shows the character set the client can handle.
• Authorization: Shows what permissions the client has.
• Host: Shows the host and port number of the client.
Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
• From: Shows the email address of the user.
HTTP | Transaction
Entity Headers:
Status Code:
Similar to those in SMTP.
It consists of three digits:
• Codes in the 100 range are Only Informational. • Codes in the 400 indicate an error at the client
site.
• Codes in the 200 range indicate a Successful Request.
• Codes in the 500 range indicate an error at the
• Codes in the 300 range redirect Client to another URL. server site.
HTTP | Transaction
Status Code:
• 100 – The initial part of the request has been received and the client may continue
with its request.
• 200 – The request is successful.
• 201 – A new URL is created.
• 302 – The requested URL is no longer used by the server.
• 400 – There is a syntax error in the request.
• 403 – Service is denied.
• 500 – There is an error, such as a crash, in the server site.
• 503 – The service is temporarily unavailable, but may be requested in the future.
Status Phrase:
This field explains the status code in the text form.
• 100 – Continue • 403 – Forbidden
• 200 – OK • 500 – Internal Server Error
• 201 – Created • 503 – Service Unavailable
• 302 – Moved Permanently
• 400 – Bad request Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
HTTP | Transaction
A response message can contain only General, Response and Entity Header.
Response Headers:
Specifies the server’s configuration and special information about the request.
• Accept-range: Shows if server accepts the range requested by client.
Client Server
HTTP | Version Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
• Remote Login
FTP establishes two connections between the hosts. One connection is used for DATA TRANSFER
and the other for CONTROL INFORMATION (commands and responses).
The control connection uses very simple rules of communication. The data connection, on the
other hand, needs more complex rules due to the variety of data types transferred.
The two FTP connection, control and data, uses different strategies and different port numbers.
Control Connection
The FTP client and server, which run on different computers, must communicate with each other.
Both computers may use different operating systems, different character sets, different file structures,
and different file formats. FTP must make this HETEROGENEITY COMPATIBLE.
FTP uses two different approaches, one for the control connection and one for the data connection.
Each command or response is only one short line so need not to worry about the file format or file
structure.
Each line is terminated with a 2-character (carriage return and line feed) end-of-line token.
FTP | Communication Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
The client must define the type of file to be transferred, the structure of the data, and the
transmission mode.
Before sending the file through the data connection, there is a need to prepare for the transmission
through the control connection.
File Type:
FTP can transfer one of the following file types across the data connection:
• ASCII: This is the default format for transferring text file.
• EBCDIC
• Image File: This is the default format for transferring binary files.
Data Structure:
FTP can transfer a file across the data connection using one of the following interpretations about
the structure of the data:
• File Structure (Default): The file has no structure. It is a continuous stream of bytes.
• Record Structure: The file is divided into records. This can be used only with text file.
• Page Structure: The file is divided in to pages, with each page having a page number and a
page header. The pages can be stored and accessed randomly or sequentially.
FTP | Communication Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
Transmission Modes:
• Stream Mode: It is the default mode. Data are delivered from FTP to TCP as a continuous
stream of bytes. TCP is responsible for fragmenting data into appropriate size. The
connection is automatically closed if the transforming data is in the stream of bytes.
Otherwise, the sender will close the connection (by putting EOF character at the end).
• Block Mode: In block mode, the data is transferred from FTP to TCP in the form of blocks,
and each block is preceded by a 3-byte header. The first byte of the block contains the
information about the block (block descriptor) and the other two bytes contain the size of the
block in bytes.
• Compressed Mode: If the file is big, the data can be compressed. The compression
method normally used in run-length encoding.
FTP | Command Processing & File Transfer
Command Processing
The user can access those files without any username or password.
The username is set to anonymous and the password to the guest by default.
The access of the user is very limited. For example, the user can copy the files but not allowed to
navigate through directories.
Trivial File Transfer Protocol (TFTP) is designed for these types of file transfer.
It is so simple that the software package can fit into the read-only memory of a diskless workstation.
Allow the user to log on to a remote computer. After logging on, a user can use the services
available on the remote computer and transfer the results back to the local computer.
TErminaL NETwork (TELNET) is one of such a client-service program. This is the standard TCP/IP
protocol for virtual terminal service.
The mechanism to access a remote computer is complex. This is because every computer and its
operating system accepts a special combination of characters as tokens.
Example: EOF token in a computer running the DOS is Ctrl+z, while the UNIX recognizes Ctrl+d.
If we want to access any remote computer in the world, we must first know what type of computer
we will be connected to, and we must install the specific terminal emulator used by that computer.
TELNET solves this problem by defining a universal interface called the Network Virtual Terminal
(NVT) character set.
Data Character:
This is an 8-bit character set in which the seven lowest order bits are the same as ASCII and the
highest order bit is 0.
Control Character:
Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
This is an 8-bit character set in which the highest order bit is 1.
TELNET| Embedding Dr. Nand Kr. Jyotish, IIT-ISM (Dhanbad)
TELNET uses only one TCP connection. Same connection is used for sending both data and
control.
The server uses the well-known port 23 and the client uses an ephemeral port.
TELNET accomplishes this by embedding the control characters in the data stream. However, to
distinguish data from control characters, each sequence of control characters is preceded by a special
control character called Interpret As Control (IAC).
Example:
Imagine a user wants a server to display a file (named “file1”) on a remote server. Command used is
cat filea.
The user uses the backspace key to correct this situation:
cat filea<backspace>1
User cannot edit locally, the editing is done at the remote server.
The backspace character is translated into two remote characters
(IAC EC), which is embedded in the data and sent to the remote
server.
[IAC – Interpret as Control: 11111111 = 255] [EC – Erase Character Command: 11110111 = 247]