Sie sind auf Seite 1von 27

Application Layer

Computer Networking by Kurose & Ross

CCN
Lecture 21

Web and HTTP


Web page consists of objects Object can be HTML file, JPEG image, Java applet, audio file, Each object is addressable by a URL A Universal resource locator (URL) is a specific character string that define a reference to an Internet object Example URL:
www.someuni.edu host name /someDept/pic.gif path name

request-response Protocol
HTTP functions as a request-response protocol in the client-server computing model. In HTTP, a web browser, for example, acts as a client, while an application running on a computer hosting a web site functions as a server. The client submits an HTTP request message to the server. The server, which stores content, or provides resources, such as HTML files, or performs other functions on behalf of the client, returns a response message to the client. A response contains completion status information about the request and may contain any content requested by the client in its message body.

HTTP
HTTP: hypertext transfer protocol Webs application layer protocol Client/server model

PC running Explorer

client: browser that requests, receives, displays Web objects server: Web server sends objects in response to requests
Mac running Navigator

Server running Apache Web server

HTTP 1.0 HTTP 1.1

HTTP
Uses TCP:
client initiates bi-directional TCP connection (via socket) to server, port 80 server accepts TCP connection from client HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server)

HTTP is stateless
server maintains no information about past client requests

Messages encoded in text

TCP connection closed

HTTP non-persistent
HTTP/1.0 One request/response per connection

simple to implement server accept request, responds, and closes connection

Problem: If requires multiple objects from same server Disadvantages

Connection setup latency (TCPs three-way handshake)




Several extra round trips added to transfer Connection handling, extra packets

Server and network overhead




Single Non-Persistent
Client
0 RTT
Client opens TCP connection

Server
SYN

SYN

1 RTT
Client sends HTTP request for HTML

DAT ACK

ACK DAT FIN ACK


Server reads from disk

2 RTT
FIN ACK SYN

SYN

3 RTT
Client sends HTTP request for image

ACK DAT
Server reads from disk

ACK

4 RTT
Image begins to arrive

DAT

Persistent HTTP connections


HTTP/1.1 Server leaves connection open after sending response Subsequent HTTP messages between same client/server sent over open connection Several requests/responses on one TCP connection

On same TCP connection: server, accept request, responds, accept new request,.

Benefits greatest for small objects

Persistent HTTP connection


Client
0 RTT
Client sends HTTP request for HTML

Server

DAT ACK DAT


Server reads from disk

1 RTT
Client sends HTTP request for image

ACK DAT ACK


Server reads from disk

DAT

2 RTT
Image begins to arrive

Types of HTTP messages


Two types of HTTP messages:

Request Response

HTTP Request Message


Start line in HTTP messages is called a request line Its has a three-fold purpose:

to indicate the command or action that the client wants performed; to specify a resource upon which the action should be taken; and to indicate to the server what version of HTTP the client is using.

The formal syntax for the request line is:


<METHOD> <request-url> <HTTP-VERSION>

GET /index.html HTTP/1.1

Method

The method is simply the type of action that the client wants the server to take; it is always specified in upper case letters. There are eight standard methods defined in HTTP/1.1, of which three are widely used: GET, HEAD and POST.

request-url

Define to open first page of webpage

HTTP-VERSION: Using which version of http

HTTP Request Message


HTTP request message:

ASCII (human-readable format)

request line (GET, POST, HEAD commands)

GET /index.html HTTP/1.1 Host: www.ucp.edu.pk User-agent: Mozilla/4.0 header Accept:text/html,text/plain lines Connection: keep-alive Accept-language:english (extra line feed)

Next line indicates end of header

HTTP Request Line


HTTP/1.0 GET

Return object Send data to server (forms) Asks for the response identical to the one that would correspond to a GET request, but without the response body. This is useful for retrieving written in response headers, without having to transport the entire content.

POST

HTTP/1.1 GET, POST, HEAD PUT,DELETE, OPTIONS, TRACE, CONNECT

HEAD

HTTP Response Message


status line (protocol status code status phrase) HTTP/1.1 200 OK Location: http://www.ucp.edu.pk/ Connection close Date: Mon, 09 JAN 2012 12:00:15 Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 2004... Content-Length: 20 byte Content-Type: text/html data data data data data ...
<html> <body> <center>UCP</center> Mysite </body> </html>

header lines

data, e.g., requested HTML file

The status code 200 indicates that this is a successful response to a request

HTTP Response Format


Status-line
HTTP

version 3 digit response code


1XX informational  2XX success  3XX redirection  4XX client error  5XX server error


HTTP Response Status Codes


A few sample codes:

200 OK

request succeeded, requested object later in this message requested object moved, new location specified later in this message (Location:) request message not understood by server requested document not found on this server

301 Moved Permanently

400 Bad Request

404 Not Found

505 HTTP Version Not Supported

DATA FROM OUR PC TO UCP SITE

128.143.71.21 is not on my local network. 128.143.71.21 is on packet to my Therefore, I need to send the my local network. defaultTherefore, I can send the packet directly. gateway with address 192.168.1.1
DNS: The IP address of ARP: What is the MAC ucp.edu.pk is ARP: The MAC address of address of 192.168.1.1? 128.143.71.21 192.168.1.1 is 00:e0:f9:23:a8:20 ARP: What is the MAC ARP: The of 128.143.71.21? address MAC address of 128.143.71.21 is 00:20:af:03:98:28

DNS: What is the IP address of ucp.edu.pk?

frame

frame

DATA FROM OUR PC TO OUR ROUTER

OUR PC: http page Source IP Address: 192.168.1.5 Source MAC Address: 00:f7:09:56:a5:bf

Our Router: Destination IP Address: (ucp.edu.pk) 128.143.71.21 Destination MAC Address: 00:e0:f9:23:a8:20

ENCAPSULATION

http page Source IP Address: 192.168.1.5 (PC) Source MAC Address: 00:f7:09:56:a5:bf (PC)
Source MAC ADDRESS: 00:f7:09:56:a5:bf (OUR PC) Source IP ADDRESS: 192.168.1.5 (OUR PC) Destina IP ADDRESS: 128.143.71.21 (UCP.EDU.PK)

Destination IP Address: (ucp.edu.pk) 128.143.71.21 Destination MAC Address: 00:e0:f9:23:a8:20 (Router)


Source Port Number: 58631 (RANDOM) Destination Port Number: 80 (HTTP)
GET /index.html HTTP/1.1 Host: www.ucp.edu.pk User-agent: Mozilla/4.0 Accept:text/html,text/plain Connection: keep-alive Accept-language:english

Destina MAC ADDRESS: 00:e0:f9:23:a8:20 (OUR ROUTER)

FRAMES DATALINK Layer

PACKET NETWORK Layer

SEGMENT TRANSPORT Layer

DATA Application Layer

PAT: Port Address Translation


Public translation table WAN side addr LAN side addr
138.76.29.7, 5001 192.168.1.5, 58631

S: 192.168.1.5, 58631 D: 128.143.71.21, 80

192.168.1.5

1 2
S: 138.76.29.7, 5001 D: 128.143.71.21, 80

192.168.1.1
S: 128.143.71.21, 80 D: 192.168.1.5, 58631

138.76.29.7
S: 128.143.71.21, 80 D: 138.76.29.7, 5001

Application data

Application Data in this frame GET /index.html HTTP/1.1 Host: www.ucp.edu.pk User-agent: Mozilla/4.0 Accept:text/html,text/plain Connection: keep-alive Accept-language:english

Ethernet Header

IP Header

TCP Header Ethernet frame

Application data

Ethernet Trailer

TCP Header

Ethernet Header

IP Header

TCP Header Ethernet frame

Application data

Ethernet Trailer

IP Header
32 bits
version (4 bits) header length DS ECN flags (3 bits) Total Length (in bytes) (16 bits) Fragment Offset (13 bits) Header Checksum (16 bits)

Identification (16 bits) TTL Time-to-Live (8 bits) Protocol (8 bits)

Source IP address (32 bits) Destination IP address (32 bits)

Ethernet Header

IP Header

TCP Header

Application data

Ethernet Trailer

Ethernet frame

Frame

6 bytes destination address source address type


4 bytes

CRC

Ethernet Header

IP Header

TCP Header

Application data

Ethernet Trailer

Ethernet frame

Das könnte Ihnen auch gefallen