Chapter 2 Application Layer

 
2.1 Principle of Application Layer Protocol
The core of developing web applications is writing programs that can run on different end systems and communicate with each other over a network.
2.1.1 Network Application Architecture
Application Architecture Mainstream Architecture:
  1. Client-Server Architecture
  2. Peer-to-peer (P2P) architecture
 
Client-Server Architecture: There is an always-on host called server that serves requests (ex: web applications) from other hosts called clients.
  • a. In this architecture, there is no direct communication between clients and clients.
  • b. The server has a fixed, well-known address. This address is called an IP address.
Specific application: web ftp telnet email
The server may be overwhelmed with processing. So data centers with large numbers of hosts are used to create powerful virtual servers.

P2P structure: The application uses direct communication between intermittently connected pairs of hosts, with little reliance on the data center.
Specific application: BT Thunder Skype IPTV
Features: Self-expansion. In a P2P file sharing application, although each peer generates workload by requesting files, each peer also contributes by distributing files to other peers.
The system increases service capacity.

Hybrid application: In many instant messaging applications, the server is used to track user IP, but user-to-user messages are sent directly between user hosts.

2.1.2 Process Communication
1. Customer and Service Process
     In the scenario of a given communication session between a pair of processes, the process initiating the communication is identified as the client, and the process waiting to be contacted at the start of the session is the server.
2. An excuse between a process and a computer network
Processes send and receive messages to and from the network through a software interface called a socket.
3. Process addressing
In order for a process running on one host to send a packet to a process running on another host, the receiving process needs to have an address.
In order to identify the receiving process, two pieces of information need to be defined.
  1. host's address ip
  2. Identifier port of the receiving process defined in the destination host

2.1.3 Shipping Services Available to the Application
Classification of service requirements provided by transport layer protocols
  • Reliable data transmission: data arrives at the receiving process error-free
  • Throughput
  • Timing: Control the delay
  • safety

2.1.4 Transportation services provided by the Internet
1. TCP service
Two services are provided:
Connection-Oriented Services:
Reliable data transfer service:
2. UDP service
UDP is a lightweight transport protocol that provides no unnecessary services, it only provides minimal services. Connectionless, unreliable, out-of-order, non-blocking control.
3. Services not provided by the Internet Transport Protocol
Guarantees on throughput and timing are not provided by the transport layer protocol.

2.1.5 Application layer packets
Application layer protocols define how applications running on different end systems pass messages to each other. In particular the application layer defines:
  • Types of messages exchanged, such as request messages and response messages.
  • The syntax of various message types, such as the fields in the message and how those fields are described.
  • The semantics of the fields, that is, the meaning of the information contained in those fields.
  • Rules for when and how a process sends and responds to messages.
 

2.2 HTTP
2.2.1 HTTP Overview
The application layer protocol of the web is the Hypertext Transfer Protocol (HTTP). HTTP is implemented by two programs: a client program and a server program.
Web pages are made up of objects. An object is just a file, such as an HTML file, a JPEG graphic, a Java applet, etc.
Most web pages contain a base HTML file and several reference objects.
HTML base files refer to other objects in the page through the object's URL address.
Each URL address consists of two parts: the hostname of the server where the object is stored and the pathname of the object. For example: www.example.com/default/1.gif
www.example.com  is the hostname and /default/1.gif is the pathname.
The web browser implements the client side of HTTP, and the web server implements the server side of HTTP for storing web objects, each of which is addressed by a URL.
The server sends the requested file to the client without storing any state information about the client. So we call HTTP a stateless protocol.
 
2.2.2 Discontinuous and persistent connections
Each request/response is sent on a separate TCP connection, not a persistent connection .
All requests/responses are sent over the same TCP connection, which is persistent .
 
2.2.3 HTTP message format
2.2.3.1 HTTP request message
  General format of HTTP request message
GET /index.html HTTP/1.1       
Host: www.test.com                
Connection: close
User-agent: Mozilla/5.0
Accept-language: f r
 
The first line is the request line: method field, URL field, HTTP version field. Subsequent lines are the first line
The first line: Host: www.test.com     indicates the host address. The information provided by this header line is what the web proxy tells the cache to ask for.
Connection:close , the browser tells the server that it doesn't want to bother using persistent connections, it asks the server to close the connection after sending the requested object.
The User-agent header line specifies the user agent, which is the type of browser that sends requests to the server. The above example is the Firefox browser. The server MAY send different versions of the same object based on different types of user agents.
The Accept-language header line indicates that the user wants the French version of the object.
 
 
 
2.2.3.2 HTTP response message
General format of HTTP response message
HTTP/1.1 200 OK
Connection: close
Date: Tue, 09 Aug 2011 15:44:04 GMT
Server: Apache/2.3.3 (Centos)
Last-Modified: Tue, 09 Aug 2011 1511:03 GMT
Content-Length: 6821
Content-Type: text/html
 
(date date date date ....)
The first line is the initial state line , 6 header lines , and then the entity body, the entity of the request object.
The status line has 3 fields: the protocol version field, the status code and the corresponding information.
Header line:
The server uses the Connection:close header line to tell the client that it will close the TCP connection after sending the message.
Date: The header line indicates the log and time when the server generated and sent the response message, specifically the time when the server retrieved the object from its file system, inserted it into the response message, and sent the response message.
Server:l is similar to the User-agent field in the request message.
Last-Modified: Indicates the date and time the object was created or last modified.
Content-Length: The number of bytes in the object being sent.
Content-Type: The object in the entity body is an HTML document.
 
 
2.2.4 User interaction with the server: cookies
 
A web site wants to be able to identify a user, either because the server wants to restrict the user's access, or because it wants to associate content with the user's identity, and uses cookies for this purpose.
Cookie technology has four components:
  1. A cookie header line in an HTTP response message
  2. A cookie header line in an HTTP request message
  3. A cookie file is maintained on the client system and managed by the user's browser
  4. A backend database on the web site
A cookie can identify a user. The user may need to provide a user ID when visiting a site for the first time. In subsequent sessions, the browser passes a cookie header to the server, thereby
The user is identified to the server. So cookies can build a user session layer on top of stateless HTTP.
 
2.2.5 Web Cache
Web cache Also known as a proxy server, a web entity that serves HTTP requests on behalf of the original web server. The web cache has its own disk storage space and keeps copies of recently requested objects in the storage space.
 
2.2.6 Conditional get
The introduction of a cache has a corresponding problem, that is, the copy of the object stored in the cache may be stale and may have been modified.
The HTTP protocol has mechanisms that allow a cache to verify that its objects are up-to-date, conditional get methods .
If the request message is a get method, and the request message contains an "if-Midified-Since:" header line, the message is a conditional GET message.
Browser -> Cache -> Server -> Cache -> Browser
During the first interaction, the response message from the server to the cache contains Last-Modified.
The second interaction The cache sends this value to the server as the value of if-Midified-Since, which is used to determine whether the current cache can continue to be used.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325119581&siteId=291194637