Lecture 3
Lecture 3
Application Layer
Table of Contents
1. Context ........................................................................................................................................... 1
2. Introduction .................................................................................................................................... 2
3. Objectives ....................................................................................................................................... 2
4. Network application software ....................................................................................................... 2
5. Process communication ................................................................................................................. 3
6. Transport Layer services provided by the Internet ....................................................................... 3
7. Application Layer Protocols ........................................................................................................... 4
8. The web and HTTP .......................................................................................................................... 4
8.1. Web Terminology ................................................................................................................... 5
8.2. Overview of HTTP protocol .................................................................................................... 6
8.3. HTTP message format ............................................................................................................ 6
8.3.1. Request message ............................................................................................................ 7
8.3.2. Response message ......................................................................................................... 7
8.4. Cookies.................................................................................................................................... 7
8.5. Web caching ........................................................................................................................... 8
9. Electronic Mail on the Internet ...................................................................................................... 8
10. File Transfer Protocol ................................................................................................................. 9
11. Domain Name System (DNS) ................................................................................................... 11
12. Peer-to-Peer (P2P) .................................................................................................................... 12
12.1. BitTorrent protocol........................................................................................................... 12
13. Activities ................................................................................................................................... 12
14. Review Questions ..................................................................................................................... 13
15. Answers to review questions ................................................................................................... 14
1. Context
In the previous chapter, we gave an introduction to the Internet protocols. We discussed two
popular protocol suites, namely the ISO OSI reference model and the TCP/IP protocol suite. In this
chapter, we will discuss the conceptual and implementation facets of software that operate at the
application layer of the TCP/IP protocol suite. The Internet is implemented by the TCP/IP protocol
stack. Thus, sometimes the Internet is referred to as the TCP/IP network. In this chapter and
chapters that follow, we will use Internet and TCP/IP network interchangeably.
2. Introduction
After this chapter, if you want to know more, read Chapter 2 of James F. Kurose and Keith
W. Ross, "Networking: A top-down approach", (6th edn.).
This chapter gives a broad overview of the Internet's application software. It looks at electronic mail,
file transfer, peer-to-peer (P2P), domain name system (DNS) and the World Wide Web in terms of
their operation and protocols used for communication.
Electronic mail (email) is the electronic version of ordinary mail. Email can be used for one-to-one
communication, in the same way as conventional mail is, but its electronic nature makes other
patterns of communication, including one-to-many and many-to-one, equally feasible.
File transfer applications allow users to share anything on the network that can be stored in a file,
including information, images and software.
Peer-to-peer applications make intermittently connected hosts, called peers, communicate directly
with each other without passing through the intermediary computer. A popular peer-to-peer
application is BitTorrent.
The World Wide Web (WWW) holds a distributed collection of information in interlinked files held
by particular computers known as Web servers. This information can be accessed by any device
running a Web browser like Google Chrome.
3. Objectives
At the end of this module, you should be able to:
5. Process communication
An application is also called a process. A process is basically a running application on one
end system. In this chapter, we will use application and process interchangeably.
When a process wants to send a message, it does so by using the services of the transport layer. The
software interface between the transport layer and the application layer is called a socket. From the
programmer standpoint, a socket is a software construct which enables applications to view
networking as if it were file I/O (input/output) — a program can read from a socket or write to a
socket as simply as reading from a file or writing to a file.
For processes running on different computers to communicate, an addressing mechanism must be
used. The process on a host is identified by a port number. A port number is a number between 0
and 65536 assigned to the running process by the operating system. A host on the Internet can run
more than one network application. Each application on one host is assigned a unique port number
for identification. Popular Internet applications have been assigned standard port numbers. For
example, HTTP uses port 80 and FTP uses port 21. Figure 2.1 illustrates how two Internet
applications identify each other for communication.
• <host name>: a human-friendly rendering of the Internet address of the host holding the
required Web page
• <file path name>: denotes the path name for the file on that host
which is taken as a request to the computer named www.uct.ac.za for the file
/courses/index.html'.
2. Receive request: The named computer (in this case, a Web server) receives the request and
locates the file in its file store.
3. Send response: The Web server sends the requested file to the requesting computer. The file is
of a particular type and assumes a well-known form.
4. Receive response: The client computer receives the file. In this case, having received it, one of
the functions of the browser running on the client computer is to cause it to be displayed.
HTTP uses the TCP protocol from the transport layer for client-server interaction because reliability
is of greater concern in Web applications. TCP guarantees delivery of application messages without
error and in proper order. The Web client initiates the TCP connection with the server. Once the
interaction is complete, the TCP connection is closed. The HTTP server does not keep any
information about the client. Once the TCP connection closes, the server forgets about the client.
Because a server does not maintain the state of a client, HTTP is said to be a stateless protocol.
The request message is sent by the Web client to the Web server to request for a Web page.
The request message is made up of three parts, namely the request line, header lines and
the message body.
1. Request line: This is the start line that begins all HTTP request messages. It has three fields:
a) Method: The method can take values GET, POST, HEAD, PUT and DELETE. The Web
client uses the GET method when it wants to request for an object.
b) URL: The URL field holds the name of the object requested by the Web client.
c) Version: Specifies the version of HTTP used.
2. Header lines: Header lines allow the Web client to pass additional information about the
request to the server. Examples of header lines include User-Agent and Accept.
3. Message body: When the Web client uses the POST method to send a request to the server,
the entity body holds the entered values in the form of the HTML document.
The response message is sent by the Web server in response to the request from the Web
client. Like requests, responses are made up of three parts, namely the status line, header
lines and the message body.
1. Status line: This is the start line of all HTTP response messages. It has three fields:
Version field: Like in the request message, the version field holds information about
the version number of the HTTP used.
Status code and phrase fields: The status code and associated phrase indicates the
result of the request. Common status codes and phrases include:
o 200 OK: The request is successful.
o 301 Moved Permanently: The requested resource has been moved
permanently.
o 400 Bad Request: The request could not be understood.
o 404 Not Found: Requested resource not found.
2. Header lines: Like in the request message, header lines allow the Web server to pass
additional information to the Web client about the response.
3. Message body: The entity body contains the requested object.
8.4. Cookies
As mentioned earlier, the HTTP server does not retain any information about the client once
the TCP connection is terminated. However, some Web applications need to keep the state
of a client. For example, if you are doing online shopping, the server must keep track of all
the products you have put in your online basket. HTTP servers use cookies to keep the state
of the client.
Cookies have four components:
1. Website database: If the Web server wants to use cookies after receiving a request from the
Web client, it generates a unique identification number and stores it in its database.
2. HTTP response-message cookie header line: The cookie header line in the response
message holds the unique identification number generated by the server.
3. Cookie file: A cookie file is kept on the user’s end system and is managed by the user’s
browser. When the browser receives an HTTP response message with a cookie header line
set, the browser extracts the unique identification number and appends a line in the cookie
file. An entry in the cookie file includes the hostname and the unique identification number.
4. HTTP request-message cookie header line: Before the Web client sends a request to the
Web server, it checks the cookie file for any entry that matches the Web server’s name. If
the match is found, the associated unique identification number is set in the HTTP request-
message cookie header line.
Most popular Web applications like Facebook, Twitter, Amazon and Google use cookies for
Web client identification.
One of the benefits of deploying a Web cache in a network is that it reduces response time for a
client request. For example, University of Cape Town can deploy a Web cache in its network and
point all devices to it. In this way, the university can substantially improve client response time,
especially if the link between the university and the Internet is slow.
Mail server: Mail servers hold incoming emails. Each recipient has a mailbox in the mail
server. The mailbox manages and maintains emails that have been sent to a recipient.
User agent: A user agent is software like Microsoft Outlook, that allows users to compose
and send emails.
SMTP: Simple Mail Transfer Protocol (SMTP) is the principal protocol for Internet email.
SMTP defines how mail servers exchange emails. It also defines how user agents send emails
to the mail server. SMTP uses TCP protocol for communication.
POP3: Post Office Protocol – Version 3 (POP3) is a protocol used by the user agent to pull an
email from the mail server. The protocol uses TCP to authenticate a user with the mail
server, retrieve the email and store it locally.
IMAP: Internet Mail Access Protocol (IMAP) is also used by the user agent to pull an email
from the mail server. Unlike POP3, IMAP allows users to keep emails in the mail server. This
allows users to access the same email from different devices.
We now demonstrate how a sender sends an email to the recipient using the components
mentioned above.
1. The message sender uses the user agent to compose the message. The agent uses SMTP for
transmission to the local mail server. A typical message has the following:
From: Specifies the sender's address. Addresses take the form
'mailbox@domain_name' - for example, [email protected].
To: Specifies the receiver’s email address.
Subject: is optional. If present, it specifies the subject of the email.
Message body: is also optional. If present, it holds the message.
2. The mail server converts the domain name to the address of the destination email server
and puts the message on the network.
3. The network routes the messages to the destination mail server.
4. The destination mail server assembles the message and places it in the recipient's mailbox.
5. The recipient's user agent pulls the email using POP3 or IMAP.
FIGURE 2.5: TCP CONNECTION BETWEEN THE FTP CLIENT AND SERVER
The client communicates with the server by sending commands using the TCP control connection.
Some common client commands include:
USER username: Used to send the username
Each command sent by the client is followed by a reply from the server. Some typical
replies, along with their possible messages, are as follows:
331 Username OK, password required
DNS clients are application-layer programs that allow hosts to query DNS servers. They are installed
on host devices and use UDP protocol from the transport layer to send requests to the DNS servers.
To illustrate the interaction between the DNS client and the DNS server hierarchy, let’s look at an
example below.
Let’s assume the client wants to determine the IP address for the hostname www.hubpages.com.
The following events will take place.
1. The client first will contact the local name server.
2. The local name server contacts one of the root servers, which returns IP addresses for TLD
servers for the top-level domain com.
3. The local name server then contacts one of these TLD servers, which returns the IP address
of an authoritative server for hubpages.com.
4. The local name server contacts one of the authoritative servers for hubpages.com, which
returns the IP address.
5. Finally, the local name server sends the IP address of hubpages.com back to the client.
13. Activities
Activity 1
Develop a simple Web server in Python that is capable of processing only one request. Specifically,
your Web server will:
1. create a connection socket when contacted by a client (browser);
2. receive the HTTP request from this connection;
3. parse the request to determine the specific file being requested;
4. get the requested file from the server’s file system;
5. create an HTTP response message consisting of the requested file preceded by header
lines;
6. send the response over the TCP connection to the requesting browser.
If a browser requests a file that is not present in your server, your server should return a
“404 Not Found” error message.
Activity 2
Create a simple mail client in Python that sends email to any recipient. Your client will need to
establish a TCP connection with a mail server (e.g. a Google mail server), dialogue with the mail
server using SMTP, send an email message to a recipient (e.g. your friend) via the mail server, and
finally close the TCP connection with the mail server.
Activity 3
In this activity, you will develop a Web proxy. When your proxy receives an HTTP request for an
object from a browser, it generates a new HTTP request for the same object and sends it to the
origin server. When the proxy receives the corresponding HTTP response with the object from the
origin server, it creates a new HTTP response, including the object, and sends it to the client. This
proxy will be multi-threaded, so that it will be able to handle multiple requests at the same time.