Application Layer
Application Layer
1. Client-Server architecture
2. P2P (Peer to Peer) architecture
Client-Server Architecture
The server is always-on
while a client can be
randomly run.
The server is listening on
the network and a client
initializes the
communication.
Upon the requests from a
client, the server provides
certain services to the
client
The server has a fixed IP address Figure: Client-server architecture
There is no dedicated
server
Pairs of hosts are called
peers
The peers communicate
directly with each other
Three challenges of the P2P
applications:
1) ISP Friendly Figure:P2P architecture
2) Security
3) Incentive
Processes communicating
Controlled by OS
Addressing Processes
- IP address of the destination-host.
- Port-number that specifies the receiving-process
in the destination-host.
Transport Services Available to Applications
An application-developer should choose certain protocol according
to the type of applications.
1. Reliable Data Transfer- Reliable means guaranteeing the data
from the sender to the receiver is delivered correctly- TCP
• Unreliable means the data from the sender to the receiver may
never arrive-UDP
2. Throughput- The rate at which the sending-process can deliver
bits to the receiving-process
• Bandwidth Sensitive Applications
• Elastic Applications
3. Timing- A transport-layer protocol can provide timing-guarantees
4. Security- A transport-protocol can provide one or more security
services
Transport Services Provided by the Internet
• TCP Services
Connection-Oriented Service
Reliable Data Transfer Service
• UDP Services
Requirements of selected network
applications
Popular Internet applications
The Web & HTTP
HTTP defines
→ how clients request Web-pages from servers and
→ how servers transfer Web-pages to clients.
Non-Persistent & Persistent Connections
initiate TCP
connection Total response time = 1 RTT+ 1
RTT
RTT+ File transmission time
request
file = 2(RTT) + File transmission time
time to
RTT
transmit
file
file
received
time time
HTTP with Persistent Connections
• GET
– request an object from server
• POST
– upload information using forms
• HEAD
– asks server to leave requested object out of response
• PUT
– uploads file in entity body to path specified in URL field
• DELETE
– deletes file specified in the URL field
HTTP Response Message
Response-message
Sample commands:
• sent as ASCII text over control channel
• USER username
• PASS password
• LIST return list of file in current directory
• RETR filename retrieves (gets) file
• STOR filename stores (puts) file onto remote host
Sample return codes
• status code and phrase (as in HTTP)
• 331 Username OK, password required
• 125 data connection already open; transfer starting
• 425 Can’t open data connection
FTP issues
User Agent
• a.k.a. “mail reader”
• composing, editing, reading
mail messages
• e.g., Eudora, Outlook, elm,
Mozilla Thunderbird
• outgoing, incoming messages
stored on server
Mail Servers
• mailbox contains incoming messages for user
• message queue of outgoing (to be sent) mail messages
mail mail
server user
user server
2 agent
agent 3 6
4 5
Mail Access Protocols
• client commands:
– user: declare username C: list
– pass: password S: 1 498
S: 2 912
• server responses S: .
– +OK C: retr 1
– -ERR S: <message 1
contents>
Transaction phase, client:
S: .
• list: list message numbers C: dele 1
• retr: retrieve message by number C: retr 2
• dele: delete S: <message 1
contents>
• Quit
S: .
• Update C: dele 2
After user issues a quit command, the C: quit
mail-server removes all messages S: +OK POP3 server
signing off
IMAP
In P2P, each node (called peers) acts as a client and server at the
same time.
The peers are not owned by a service-provider.
The peers not supposed to be always listening on the Internet.
The peers are dynamic, i.e., some peers will join some peers will
leave from time to time.
P2P File Distribution
• One popular P2P file distribution protocol is
BitTorrent
Length of the file = F
Upload rate for the server = us
Upload rate for ith computer = ui
Download-rate for ith computer = di
Distribution-time for the client-server architecture = Dcs
Server needs transmit = NF bits.
Lowest download-rate of peer = dmin
Distribution-time for the P2P architecture = DP2P
Case 1: Client-Server Architecture
The server must transmit one copy of the file to each of the N peers.
– Since the server's upload rate is us, the distribution-time is at
least NF/us.
The peer with the lowest download-rate cannot obtain all F bits of
the file in less than F/dmin.
– Thus, the minimum distribution-time is at least F/ dmin.
Putting above 2 observations together, we have
Case 2: P2P Architecture
1. At the beginning of the distribution, only the server has the file.
– So, the minimum distribution-time is at least F/us.
2. The peer with the lowest download-rate cannot obtain all F bits of the
file in less than F/dmin.
– Thus, the minimum distribution-time is at least F/ dmin.
(a) A circular DHT. Peer 3 wants to determine who is responsible for key
11.
(b) A circular DHT with shortcuts
Socket Programming: Creating Network
Applications
Two types of network-applications:
• First type is an implementation whose operation is specified in a
protocol standard (RFC)
– Such an application is referred to as “open”.
– The client & server programs must conform to the rules
dictated by the RFC.
• Second type is a proprietary network-application.
– The client & server programs use an application-layer protocol
not openly published in a RFC.
– A single developer creates both the client and server programs.
– The developer has complete control over the code.
During development phase, the developer must decide whether the
application uses TCP or UDP.
Socket Programming with UDP
The client
reads a line of characters (data) from the keyboard
sends the data to the server.
2. The server receives the data and converts the characters
to uppercase.
3. The server sends the modified data to the client.
4. The client receives the modified data and displays the
line on its screen.
The client-server application using UDP
The client-side of the application
from socket import * //This line declares socket within the program.
serverName = ‘hostname’ // This line sets the server name to “hostname”. serverPort
= 12000 // This line sets the server port# to “12000”.