Unit-2:
Application Layer
Part-2
Computer Networks (CN)
GTU #3150710
Outline
Looping
• Principles of Computer Applications
• Web
• HTTP
• E-mail
• DNS
• Socket programming with TCP and UDP
USER-SERVER INTERACTIONS: COOKIE
User-Server interactions: Cookie
A small text file that is stored in the user's computer either temporarily for that session only
or permanently on the hard disk.
Cookies provide a way for the Web site to recognize you and keep track of your preferences.
The 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 the user’s end system and managed by the user’s browser
4. A back-end database at the Web site
Authorization Recommendations
Use of Cookies
User session state
Shopping carts (Web, Email)
Prof. Maulik D. Trivedi #3150710(CN) Unit 2 – Application Layer
Cookies - Example
client server
ebay 8734 usual http request msg server
cookie file creates ID
usual http response
set-cookie: 1678 1678 for user create backend
ebay 8734 entry database
amazon 1678
usual http request msg
cookie: 1678 cookie- access
specific
usual http response msg action
one week later:
access
ebay 8734 usual http request msg
amazon 1678 cookie: 1678 cookie-
specific
usual http response msg action
WEB CACHES (PROXY SERVER)
Web Caches (Proxy Server)
It satisfies HTTP requests on the behalf of an origin Web server.
The Web cache has its own disk storage and keeps copies of recently requested objects in
this storage.
HT proxy
TP
server q u est
r equ re
HT P
client TP est
HT
T
p o nse
res res origin
pon TP
se HT server
t
ues
req se
TP o n
HT res
p
TP
HT
client origin
server
Web Caches (Proxy Server) – Cont...
A user’s browser can be configured so, user’s HTTP requests are first directed to the Web
Cache.
A browser sends all HTTP requests to cache.
As an example, suppose a browser is requesting the object
[Link]
Object in cache returns to client browser.
Otherwise cache requests object from origin server, then returns object to client browser.
Reduce response time for client request.
Reduce traffic on an institution’s access link.
Internet dense with caches: Insufficiency for content providers to effectively deliver content.
Web Caches (Proxy Server) – Example
Example: Institutional Network and Internet
Reduce response time for client request.
Reduce traffic on an institution’s access link.
Internet dense with caches: Insufficiency for
content providers to effectively deliver
content.
FTP (FILE TRANSFER PROTOCOL)
FTP (File Transfer Protocol)
File Transfer Protocol (FTP) is the commonly used protocol for exchanging files over the
Network or Internet.
Example: Filezilla
FTP uses the Internet's TCP/IP protocols to enable data transfer.
FTP uses client-server architecture.
FTP promotes sharing of files via remote computers with reliable and efficient data transfer.
FTP user FTP File transfer FTP
interface client server
User or
Host
Local file system Remote file system
FTP (File Transfer Protocol) – Cont…
FTP client connect FTP server at port 21 using TCP.
FTP uses two parallel TCP connections to transfer a file,
Control Connection: Used for sending control information between two
hosts.
Data Connection: To send a file.
Control Information like user identification, password, commands to change remote
directory, commands to “put” and “get” files
Client will browse remote file directory, sends commands over control
connection.
FTP server maintains “state” about user like current directory, earlier
authentication.
FTP (File Transfer Protocol) – Example
ELECTRONIC MAIL (EMAIL)
Electronic Mail (Email)
Email is an asynchronous communication medium in
which people send and read messages as convenient for
them.
Modern Email has many powerful features like:
A messages with attachments
Hyperlinks
HTML-formatted text
Embedded photos
Email is fast, easy to distribute, and inexpensive.
High level view of Internet mail system and its key
components.
User agents
Mail servers
Simple Mail Transfer Protocol (SMTP)
Email - Cont…
User Agent user
agent
User agents allow users to read, reply to, forward, save,
and compose messages. mail user
server
E.g. Microsoft Outlook and Apple Mail. agent
Mail servers: SMTP mail user
A mailbox contains incoming messages for user. server agent
A message queue of outgoing (to be sent) mail SMTP
messages.
SMTP user
SMTP mail
agent
server
It is a principal application layer protocol between mail user
servers to send email messages. agent
client: sending mail to server user
server: receiving mail from other different mail server agent
Outgoing
message queue
user mailbox
#3150710(CN) Unit 2 – Application Layer
SMTP
Simple Mail Transfer Protocol used in sending and receiving e-mail.
It use TCP to reliably transfer email message from client to server using port 25.
It restricts the body (not just the headers) of all mail messages to simple 7-bit ASCII.
SMTP does not use intermediate mail servers for sending mail.
If receiving end mail server is down, the message remains in sending end mail server and
waits for a new attempt.
SMTP - Example
1. Alice uses user agent to compose 4. SMTP client sends Alice’s
message to message over the TCP connection.
computer@[Link]
1)2)Alice
Alice’s
uses
user
user
agent
agent
sends
to compose [Link]’s
messagemessage to mail server places the
mail
3)4)Client
5)
SMTP
Bob’s
side
client
mail
of sends
SMTP
serverAlice’s
opens
placesTCP
message
theconnection
message
over the
inwith
Bob’s
TCP
2. Alice’s user agent sends 6) Bob invokes his user agent to read
message message
message in Bob’s mailbox.
server;
computer@[Link]
message placed
Bob’s inserver
connection
mail
mailboxmessage queue.
to her mail server; message placed 6. Bob invokes his user agent to
in message queue. read message.
3. Client side of SMTP opens TCP
connection with Bob’s mail server.
Mail Access Protocols (POP3 and IMAP)
POP3
Post Office Protocol – Version 3
IMAP
Internet Mail Access Protocol
A mail access protocol, such as POP3, is used to transfer mail from the recipient’s mail server
to the recipient’s user agent.
POP3 – Post Office Version 3
POP3 is an extremely simple mail access protocol.
With the TCP connection established, POP3 progresses through three phases: authorization,
transaction and update.
In authorization, the user agent sends a username and a password to authenticate the user.
In transaction, the user agent retrieves messages, mark messages for deletion, remove
deletion marks and obtain mail statistics.
In update, after the quit command by client, ending the POP3 session; the mail server
deletes marked messages.
POP3 is designed to delete mail on the server as soon as the user has downloaded it.
IMAP - Internet Mail Access Protocol
To keeps all messages in one place: at server
The recipient can then move and organize the message into a new, user-created folder, read
the message, delete the message, move messages from one folder to another and so on.
To allow users to search remote folders for messages matching specific criteria.
Also permit a user agent to obtain components of messages, When low-bandwidth
connection between the user agent and its mail server.
In this case, user not to download all the messages in its mailbox, particularly avoiding long
messages like an audio or video clip.
DNS - DOMAIN NAME SYSTEM
DNS - Domain Name System
Alphabetic name remember IP Address
by human
It is an internet service that translates domain names into IP addresses.
It is application-layer protocol. DNS service must translate the domain name into the
corresponding IP address.
In DNS system, If one DNS server doesn't know how to translate a particular domain name, it
asks another one, and so on, until the correct IP address is returned.
DNS - Example
DNS client wants to determine the IP address for the hostname [Link]
The client first contacts one of the root servers, which returns IP addresses for TLD servers -
top-level domain .com.
Then contacts TLD servers, which returns the IP address of an authoritative server for
[Link]
Finally, contacts one of the authoritative servers for [Link], which returns the IP
address for the hostname [Link].
DNS: A distributed - hierarchical database
Root DNS Servers – Total 13
DNS – Cont…
Top-level domain (TLD) servers:
It is responsible for com, org, net, edu, aero, jobs, museums, and all top-level country domains, e.g.: uk,
fr, ca, jp
Network Solutions maintains servers for .com TLD
Education for .edu TLD
Authoritative DNS servers:
To organization’s own DNS servers, providing authoritative hostname to IP mappings for organization’s
named hosts.
It can be maintained by organization or service provider.
Local DNS name servers:
It does not strictly belong to hierarchy
when host makes DNS query, query is sent to its local DNS server.
It acts as proxy, forwards query into hierarchy.
DNS - Example
DNS Name Resolution Example
Iterated Query: root DNS server
A host at [Link] wants IP address for
[Link]
2
3
TLD DNS server
4
local DNS server
[Link]
7 6
1 8
authoritative DNS server
[Link]
requesting host
[Link]
[Link]
Prof. Maulik D. Trivedi #3150710(CN) Unit 2 – Application Layer
DNS Name Resolution Example
Recursive Query: root DNS server
A host at [Link] wants IP address for [Link]
2 3
7
6
TLD DNS
server
local DNS server
[Link] 5 4
1 8
authoritative DNS server
[Link]
requesting host
[Link]
[Link]
Prof. Maulik D. Trivedi #3150710(CN) Unit 2 – Application Layer
DNS – Cont...
Distributed database design is more preferred over centralized design to implement DNS in
the Internet.
A single point of failure: If the DNS server crashes then the entire Internet will not stop.
Traffic volume: With millions of device and users accessing its services from whole globe at
the same time.
A Single DNS Server cannot handle huge DNS traffic but with distributed system its
distributed and reduce overload on server.
Distant centralized database: A single DNS server cannot be “close to” all the querying
clients.
If it is in New York City, then all queries from Australia must travel to the other side of the globe, perhaps
over slow and congested links cause significant delays.
Maintenance: To keep records for all Internet hosts. it would have to be updated frequently
to account for every new host.
SOCKET PROGRAMMING
Socket Programming
Socket is interface between application and network.
An application creates a socket.
Two type of socket:
TCP Socket – Reliable Transmission
UDP Socket – Unreliable Transmission
Once configured the application can pass data to the socket for transmission and receive
data from the socket (transmitted through the network by some other host).
application application
socket controlled by
process process app developer
transport transport
network network controlled
link
by OS
link Internet
physical physical
Type of Socket
SOCK_STREAM SOCK_DGRAM
E.g. TCP E.g. UDP
Reliable delivery Unreliable delivery
In-order guaranteed No order guarantees
Connection-oriented Connection-less
Bidirectional Unidirectional
App D1
App
3 2 3 2
1 D2
socket Dest. 1 socket
D3
Client-Server socket interaction: UDP
server (running on serverIP) client
create socket:
create socket, port= x: clientSocket =
serverSocket = socket(AF_INET,SOCK_DGRAM)
socket(AF_INET,SOCK_DGRAM)
Create datagram with server IP and
port=x; send datagram via
read datagram from clientSocket
serverSocket
write reply to
serverSocket read datagram from
specifying clientSocket
client address,
port number close
clientSocket
Client-Server socket interaction: TCP
server (running on hostid) client
create socket,
port=x, for incoming
request:
serverSocket = socket()
wait for incoming create socket,
TCP
connection request connect to hostid, port=x
connectionSocket = connection setup clientSocket = socket()
[Link]()
send request using
read request from clientSocket
connectionSocket
write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
Outline - Summary
Principles of Computer Applications
Browser, Web Server, Email, P2P Applications etc…
Application Layer (TCP – UDP Services)
Web (Web Pages – Objects like html, jpeg, mp3, etc…)
HTTP (TCP connection, port-80, persistent & non-persistent conn.), Request & Response
Message format, Cookies, Web caches, FTP, Port-21
E-mail (User agent, Mail Server, SMTP port - 25), POP3, IMAP
DNS (Domain names to IP Address), hierarchy structure
Socket programming with TCP and UDP (TCP – Sock_Stream, UDP – Sock_DGram)
Computer Networks (CN)
GTU #3150710
Thank
You
Prof. Maulik Trivedi
Computer Engineering Department
Darshan Institute of Engineering & Technology, Rajkot
[Link]@[Link]
9998265805