Lecture Notes Computer Networks
Lecture Notes Computer Networks
1
Contents
1 Application Layer 3
1.1 DNS - Domain Name System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 The Web and HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.1 Overview of HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.2 Non-Persistent and Persistent Connections . . . . . . . . . . . . . . . . . . . . . . 3
1.2.3 HTTP Message Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.4 User-Server Interaction: Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.5 Web Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 Electronic Mail in the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3.1 STMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3.2 Comparison with HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3.3 Mail Message Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3.4 Mail Access Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2
1 Application Layer
1.1 DNS - Domain Name System
1.2 The Web and HTTP
1.2.1 Overview of HTTP
• The HyperText Transfer Protocol (HTTP), the Web’s application-layer protocol, is at the
heart of the Web. It is defined in [RFC 1945] and [RFC 2616]. HTTP is implemented in two pro-
grams: a client program and a server program. The client program and server program, executing
on different end systems, talk to each other by exchanging HTTP messages. HTTP defines the
structure of these messages and how the client and server exchange the messages.
• A Web page consists of objects. An object is simply a file-such as an HTML file, a JPEG image, a
Java applet, or a video clip-that is addressable by a single URL. Most Web pages consist of a base
HTML file and several referenced objects. Each URL has two components: the hostname of the
sever that houses the object and the object’s path name.
• HTTP defines how Web request Web pages from Web servers and how servers transfer Web pages
to clients.When a user requests a Web page (for example, clicks on a hyperlink), the browser sends
HTTP request messages for the objects in the page to the server. The server receives the requests
and responds with HTTP response messages that contain the objects.
• HTTP uses TCP as its underlying transport protocol, that provides a reliable data transfer
service to HTTP.
• HTTP is said to be a stateless protocol. HTTP sever maintains no information about the clients.
3
The header line Host: www.someschool.edu specifies the host on which the object resides
The User-agent: header line specifies the user agent, that is, the browser type that is making the
request to the server. Here the user agent is Mozilla/5.0, a Firefox browser
The GET method is used when the browser requests an object, with the requested object identi-
fied in the URL field. In this example, the browser is requesting the object /somedir/page.html
the Accept-language: header indicates that the user prefers to receive a French version of the
object, if such an object exists on the server; otherwise, the server should send its default version.
• Response messages:
HTTP/1.1 200 OK
Connection: close
Date: Tue, 18 Aug 2015 15:44:04 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Tue, 18 Aug 2015 15:11:03 GMT
Content-Length: 6821
Content-Type: text/html
(data data data data data ...)
• Status line: the protocol version field, a status code, and a corresponding status message.
• Header lines:
– The Connection: close header line to tell the client that it is going to close the TCP
connection after sending the message.
– The Date: header line indicates the time and date when the HTTP response was created
and sent by the server. Note that this is not the time when the object was created or last
modified; it is the time when the server retrieves the object from its file system, inserts the
object into the response message, and sends the response message
– The Server: header line indicates that the message was generated by an Apache Web server
– The LastModified: header line indicates the time and date when the object was created or
last modified. The Last-Modified: header, which we will soon cover in more detail, is critical
for object caching, both in the local client and in network cache servers (also known as proxy
servers).
– The Content-Length: header line indicates the number of bytes in the object being sent.
4
– The Content-Type: header line indicates that the object in the entity body is HTML text.
(The object type is officially indicated by the Content-Type: header and not by the file
extension.)
• Some common status codes and associated phrases include:
– 200 OK: Request succeeded and the information is returned in the response.
– 301 Moved Permanently: Requested object has been permanently moved; the new URL is
specified in Location : header of the response message. The client software will automatically
retrieve the new URL.
– 400 Bad Request: This is a generic error code indicating that the request could not be
understood by the server
– 404 Not Found: The requested document does not exist on this server.
– 505 HTTP Version Not Supported: The requested HTTP protocol version is not supported
by the server.
• Entity body:The entity body is the meat of the message—it contains the requested object itself
(represented by data data data data data ... ).
How does a browser decide which header lines to include in a request message? How does a
Web server decide which header lines to include in a response message? A browser will generate
header lines as a function of the browser type and version (for example, an HTTP/1.0 browser will
not generate any 1.1 header lines), the user configuration of the browser (for example, preferred
language), and whether the browser currently has a cached, but possibly out-of-date, version of the
object. Web servers behave similarly: There are different products, versions, and configurations,
all of which influence which header lines are included in response messages.
5
• Cookie technology has four components: (1) a cookie header line in the HTTP response message;
(2) a cookie header line in the HTTP request message; (3) a cookie file kept on theuser’s end system
and managed by the user’s browser; and (4) a back-end database at the Web site.
• Cookies can also be considered as an invasion of privacy. Using a combination of cookies and
user-supplied account information, a Web site can learn a lot about a user and potentially sell this
information to a third party.
6
• A Web cache can substantially reduce the response time for a client request and traffic on an
institution’s access link to the internet.The institution does not have to upgrade bandwidth as
quickly, thereby reducing costs. Furthermore, it can reduce Web traffic in the internet as a whole.
7
delay of slightly greater then 1.2 sec. And the cost is low.
• Problem: The copy of an object residing in the cache may be stale, the object housed in the Web
server may have been modified since the copy was cached at the client.
• Therfore conditional GET. An HTTP request message is a so-called conditional GET message if
(1) the request message uses the GET method and (2) the request message includes an If-Modified-
Since: header line.
• Example, a proxy cache sends a request message to a Web server:
The Web Server sends a response message with the requested object to the cache:
8
• A typical message starts its journey in the sender’s user agent, travels to the sender’s mail server,
and travels to the recipient’s mail server, where it is deposited in the recipient’s mailbox.
• It uses the reliable data transfer service of TCP. SMTP has two sides: a client side, which executes
on the sender’s mail server, and a server side, which executes on the recipient’s mail server.
1.3.1 STMP
• SMTP requires binary multimedia data to be encoded to ASCII before being sent over SMTP; and
it requires the corresponding ASCII message to be decoded back to binary after SMTP transport.
• SMTP does not normally use intermediate mail servers for sending mail, even when the two mail
servers are located at opposite ends of the world
• How SMTP transfers a message:
First, the client SMTP (running on the sending mail server host) has TCP establish a connection
to port 25 at the server SMTP (running on the receiving mail server host). If the server is down,
the client tries again later. Once this connection is established, the server and client perform
some application-layer handshaking—just as humans often introduce themselves before transferring
information from one to another, SMTP clients and servers introduce themselves before transferring
information. During this SMTP handshaking phase, the SMTP client indicates the email address
of the sender (the person who generated the message) and the e-mail address of the recipient.
Once the SMTP client and server have introduced themselves to each other, the client sends the
message. SMTP can count on the reliable data transfer service of TCP to get the message to the
server without errors. The client then repeats this process over the same TCP connection if it has
other messages to send to the server; otherwise, it instructs TCP to close the connection.
9
• Example transcript of messages exchanged between SMTP client and server:
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM: <alice@crepes.fr>
S: 250 alice@crepes.fr ... Sender ok
C: RCPT TO: <bob@hamburger.edu>
S: 250 bob@hamburger.edu ... Recipient ok
C: DATA
S: 354 Enter mail, end with "." on a line by itself
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 hamburger.edu closing connection
• SMTP requires each message, including the body of each message, to be in 7-bit ASCII format.If
the message contains characters that are not 7-bit ASCII (for example, French characters with
accents) or contains binary data (such as an image file), then the message has to be encoded into
7-bit ASCII. HTTP data does not impose this restriction.
• HTTP encapsulates each object in its own HTTP response message. SMTP places all of the
message’s objects into one message
10
From: alice@crepes.fr
To: bob@hamburger.edu
Subject: Searching for the meaning of life.
POP3
• With the TCPconnection established, POP3 progresses through three phases: authorization, trans-
action, and update.
• Downloading and delete or download and keep. The transaction will look like this:
• A problem with this download-and-delete mode is that the recipient, Bob, may be nomadic and
may want to access his mail messages from multiple machines, for example, his office PC, his home
PC, and his portable computer.
11
• In the download-and-keep mode, the user agent leaves the messages on the mail server after down-
loading them. In this case, Bob can reread messages from different machines; he can access a
message from work and access it again later in the week from home.
IMAP
• The POP3 protocol does not provide any means for a user to create remote folders and assign
messages to folders.
• An IMAP server will associate each message with a folder; when a message first arrives at the server,
it is associated with the recipient’s INBOX folder. The recipient can then move the message into
a new, user-created folder, read the message, delete the message, and so on. The IMAP protocol
provides commands to allow users to create folders and move messages from one folder to another.
IMAP also provides commands that allow users to search remote folders for messages matching
specific criteria. Note that, unlike POP3, an IMAP server maintains user state information across
IMAP sessions—for example, the names of the folders and which messages are associated with
which folders.
Web-Based E-mail
The user agent is an ordinary Web browser, and the user communicates with its remote mailbox via
HTTP.
Alice’s mail server, however, still sends messages to, and receives messages from, other mail servers using
SMTP.
12