This article has participated in the activity of "New person creation Ceremony", and started the road of digging gold creation together.

1. Application layer Overview

(1) Previously

  1. Physical layer: Solve the problem of what signal is used to transmit bits
  2. Data link layer: Solves the problem of packet transmission over a network (or a link)
  3. Network layer: Solve the problem of packet transmission (routing) over multiple networks
  4. Transport layer: Addresses network-based communication between processes
  5. Application layer: Solves the problem of implementing specific network applications through the interaction of application processes.

(2) Definition of application layer

Application layer is the top layer of computer network architecture, the ultimate goal of designing and constructing computer network, and also the fastest developing part of computer network.

(3) Related applications

  1. The world wide web WWW
  2. Domain name System DNS
  3. Configure DHCP for dynamic hosts
  4. E-mail
  5. File transfer FTP and P2P file sharing
  6. Multimedia Network application

Client/server mode (C/S mode) and peer mode (P2P mode)

(1) Client/server mode (C/S mode)

  1. Client and ServerRefers to two application processes involved in communication.
  2. The client/server approach is describedRelationships between processes that serve and are served.
  3. The customer is the service requester.The server is the service provider
  4. The server alwaysIn operationAnd wait for the customer’s service request. The serverHas a fixed port number(The fixed port number of the HTTP server is 80) andFixed IP address.
  5. Since a single server computer serves multiple clients, it is common in C/S applicationsThe server machine can't keep up with the many clients. soCommon computer clusterBuild a virtual server.

application

  1. The world wide web WWW
  2. E-mail
  3. File Transfer FTP

(2) Peer-to-peer (P2P)

In P2P mode, there is no fixed service requester and service provider, and application processes distributed in the system at each end of the network edge are peer, which is called peer. Peers communicate directly with each other, and each peer is both a requestor and a provider of a service.

application

  1. P2P File Sharing
  2. Instant messaging
  3. P2P streaming media
  4. Distributed storage

3. Configure DHCP for dynamic hosts

(1) Why do dynamic hosts need to configure the protocol DHCP?

Without DYNAMIC host configuration protocol (DHCP), we manually configure the corresponding information for the host (IP address, subnet mask, default gateway, DNS server). However, this may lead to configuration errors and heavy workload. Therefore, dynamic host configuration protocol DHCP came into being.

(2) Working process of dynamic host configuration protocol DHCP

1. Search for the DHCP server

The DHCP client process sends a DHCP discovery packet (with the source IP address 0.0.0.0 and destination IP address 255.255.255.255) to the link. The packet is a broadcast packet that searches for a DHCP server on the network where the DHCP server resides, because only the DHCP server can parse the UDP packet.

2. Lease IP addresses

When the DHCP server receives a discovery packet, it sends a DHCP offer packet (the source IP address is the IP address of the DHCP server and the destination IP address is 255.255.255.255) to the link. The packet is broadcast. After receiving the packet, the DHCP client uses ARP to ensure that the selected IP address is occupied by another host.

3. Accept the IP address lease

After receiving a DHCP request packet, the DHCP sends a DHCP request packet (with the source IP address 0.0.0.0 and destination IP address 255.255.255.255) to the link. The DHCP request packet is a broadcast packet that tells the DHCP server to accept the IP address lease.

4. Confirm the IP address lease

After receiving a DHCP request packet, the DHCP server sends a DHCP confirmation packet (the source IP address is the IP address of the server, and the destination IP address is 255.255.255.255) to the link. The DHCP confirmation packet is a broadcast packet that confirms the IP address lease. After receiving the packet, the DHCP client uses ARP to ensure that the selected IP address is occupied by another host on the network.

(3) IP address renewal

1. Case 1

When the lease of an IP address expires, the DHCP client sends a DHCP request message to the DHCP server. In this case, the DHCP server sends a DHCP confirmation message to the DHCP client. The source IP address is the server IP address. The destination IP address is a rented address), then the DHCP client gets a new lease

2. Case 2

When the lease of the CORRESPONDING IP address expires, the DHCP client sends a DHCP request message (the source IP address is the lease address, the destination IP address is the server IP address) to the CORRESPONDING DHCP server, and the DHCP server sends a DHCP unconfirmation message (the source IP address is the server IP address) to the DHCP client. If the destination IP address is a rented one, the DHCP client immediately deactivates the corresponding IP address and performs dynamic allocation again.

3. 3

When the LEASE of an IP address expires, the DHCP client sends A DHCP request packet (the source IP address is the lease IP address, and the destination IP address is the server IP address) to the DHCP server. The DHCP server does not respond to the DHCP client, and the lease expires. Then the DHCP client immediately deactivates the corresponding IP address and starts the dynamic allocation process again.

Three cases are illustrated graphically

(4) DHCP relay agent

Why is a DHCP relay agent needed?

If the corresponding host and DHCP server are not on the same network, the router cannot forward broadcast packets. Therefore, a DHCP relay agent is required.

The role of DHCP relay agent

Act as a bridge between each computer and the corresponding DHCP server.

4. DNS

(1) DNS application

  1. Mapping domain names to IP addresses
  2. pingThe command

(2) The process the host goes through after entering the domain name

When a URL is entered on the user’s host, the host first looks for the IP address of the corresponding domain name in its cache. If it does not find the URL, the host sends a message to the DNS server asking, “What is the IP address of the corresponding domain name?” Is sent to the DNS server. The DNS server sends a response packet containing Corresponding IP address to the user host. This allows the user host to access the corresponding host.

(3) Can a DNS server be used on the Internet?

This is not advisable because the Internet is so large that DNS servers can become overwhelmed and the entire Internet can collapse if DNS servers fail.

(4) Naming rules of domain names

The domain name structure adopts hierarchical tree structure.

~. Level 3 domain name. Secondary domain name. Top-level domain name

  1. Root DNS serverThe root DNS server usually does not resolve domain names directlyReturns the IP address of the TOP-LEVEL domain name server of the owning top-level domain name.
  2. Top-level domain name server: These DNS serversManages all secondary domain names registered with the top-level domain name server.
  3. Domain name servers: These domain name servers manage the domain names of a zone.
  4. Local domain name server: the local domain name server (DNS) acts as a proxy and forwards the packet to the hierarchy of the DNS mentioned above.

(5) Domain name resolution process

1. Recursive query

The user host recursively queries the root DNS server, the root DNS server recursively queries the TOP-LEVEL DNS server, and the TOP-LEVEL DNS server recursively queries the domain name server. Return the query result.

2. Iterative query

The user host recursively queries the root DNS server. The root DNS server iteratively queries the user host for the next IP address. The TOP-LEVEL DNS server iteratively queries the user host for the next IP address. Return the query result.

Recursive queries will lead to too much server burden, so the general use of host-to-local DNS queries are recursive queries, and the rest are iterative queries.

cache

Why cache?

To improve DNS query efficiency and reduce the pressure on DNS servers, cache is used.

Process of caching

If you find the mapping between the domain name and THE IP address, you can save the mapping between the domain name and the IP address. When you search for the same domain name again, you can report the cache result to the user.

Caching can also be set up on the host.

5. File transfer protocol FTP

(1) What is file transfer

Transfer files from one computer over the network to another computer far away.

(2) File transfer protocol FTP

  1. FTP provides interactive access, allowing customers to specify file types and formats, and allowing access to files.
  2. FTPIt blocks the details of each computer.Therefore, it is suitable for transferring files between any computers in heterogeneous network.

(3) Two connections that must be established between FTP client and server

  1. Controls connections that remain open for the duration of the session and are used to transfer FTP-related commands.
  2. Data connections, used for file transfers, are established at each transfer and closed at the end of the transfer.
  3. By default, FTP is usedTCP21 portTo make control connections,TCP20 portData connection.

(4) Active mode

The FTP client initiates a TCP connection to establish a TCP connection for transmitting control commands. When data needs to be transmitted, the FTP client tells the FTP server to establish a TCP connection with another temporary port number of the FTP client through the command channel to establish a data channel.

(5) Passive mode

The FTP client initiates a TCP connection to establish a TCP connection for transmitting control commands. When data needs to be transmitted, the FTP client uses the command channel to inform the FTP server to enable a temporary port number to wait for the TCP connection and establish the data channel.

6. Email

(1) Email system description

The e – mail system adopts client/server mode. There are three main building blocks: the user agent, the mail server, and the protocols required for E-mail.

  1. The user agentisUser interface to E-mail system, also known as email client software.
  2. Mail serverIt’s the infrastructure of email. All ISPs on the Internet have mail serversThe function is to send and receive mail, but also responsible for maintaining the user's mailbox.
  3. The agreement includesMail Sending Protocol (SMTP) and Mail Reading Protocol (POP3).

(2) Commonly used mail sending protocols

The commonly used mail sending protocol is simple mail transfer protocol SMTP.

  1. Based on theTCPConnection, port number is25.
  2. Only ASCII text can be transmitted.
  3. Used forThe user agenttoThe mail server sends mailsAs well asSend mails between mail servers.

1. Existing problems

But only ASCII text can be sent. To solve this problem, a multipurpose Internet mail extension MIME is proposed.

2. Multipurpose Internet mail extends the MIME working process

Before using SMTP, the sender uses MIME to convert non-ASCII codes into ASCII codes, and then uses SMTP for transmission. When the receiver receives the message, MIME converts the message from ASCII to non-ASCII using MIME, and then receives it.

Basic working principle of simple mail transfer protocol SMTP

  1. The sender mail server (SMTP client) is initially sent to the receiver mail server14 SMTP commands are sent, and then the recipient mail server (SMTP server) sends the sender mail serverSend 21 SMTP replies.

  1. The receiver mail server communicates with the sender mail serverActive push server ready reply, the response code is220;

  1. The sender mail server communicates with the receiver mail serverIdentify yourself and tell yourself the domain name of the SMTP serverIf theIdentity and effective, the receiver server sends the answer code250.

  1. The sender mail server communicates with the receiver mail serverState where you are fromIf it makes sense, the receiver server sends the answer code250Otherwise, send back other error codes.

  1. The sender mail server describes itself to the receiver serverAnd whereIf theEmail is, the receiver server sends the answer code250Otherwise, send back other error codes.

  1. The sender mail server communicates with the receiver mail serverNote You are ready to send an emailIf theBe ready to receive, the receiver server sends the answer code354Otherwise, send back other error codes.

  1. The sender mail server communicates with the receiver mail serverState the content of your email

  1. The sender mail server communicates with the receiver mail serverAfter sending the content of the message, also send the closing characterIf theAccept a success, the receiver server sends the answer code250Otherwise, send back other error codes.

  1. The sender mail server communicates with the receiver mail serverNote You need to disconnect the connection, the receiver server sends the answer code221: accepts the request and disconnects.

(3) Commonly used mail reading protocols

  1. Post office protocol POP3: a very simple, limited mail reading protocol.Users can download messages from the mail server to the user's computer only in download and delete mode or download and keep mode. Users are not allowed to manage their own mail on the mail server.
  2. Internet Mail access protocol IMAP: a more powerful mail reading protocol than POP3.IMAP is an online protocol that allows users to manipulate mail server mailboxes from their own computer as if they were local.
  3. POP3 and IMAP4 use client/server mode based on TCP connection.POP3The use of port110.IMAP4The use of port143.

(4) General process of sending emails

The sender’s user agent uses SMTP to send mail to the sender mail server, and the sender mail server uses SMTP to send mail to the recipient mail server. The recipient’s user agent uses POP3 to fetch messages from the recipient’s mail server.

(5) E-mail based on the World Wide Web

You can write, send, receive, read and manage E-mail by logging in to a web site using a browser (providing a user name and password). This works much like IMAP, except that there is no special user agent installed on the user’s computer, just a common Web browser.

In this mode, HTTP is used between the user’s browser and the mail server’s website, while SMTP is used between the mail server.

World Wide Web WWW

(1) Introduction to the World Wide Web

The Web is not some special computer network. It is a large – scale, online information store, is running on the Internet is a distributed application.

(2) Relevant popular browsers and their engines

The most important part of the browser is the rendering engine, the browser kernel. Responsible for page parsing and display.

  1. Chrome : Blink
  2. Firefox : Gecko
  3. Safari : WebKit
  4. Opera : Blink
  5. Internet Explorer : Trident

(3) Uniform Resource Locator (URL)

The World Wide Web uses uniform Resource Locator (URL) to indicate the location of any kind of resource on the Internet

Its composition format:

< protocol >://< host >:< port >/< path >

(4) Documents on the World Wide Web

The most basic components of a Web document are HTML, CSS, and JavaScript.

  1. HTML: Hypertext markup language (HTML), which uses a variety of tags to describe the structure and content of a web page.
  2. CSS: Cascading style sheets (CSS) describe the style of a web page from an aesthetic point of view.
  3. JavaScript: A scripting language (unrelated to Java) that controls the behavior of web pages.

(5) Hypertext transfer protocol HTTP

HTTP defines how browsers request Web documents from web servers and how web servers send Web documents to browsers.

1.HTTP application process

First, the browser establishes a TCP connection to the server on port 80. The browser sends an HTTP request packet to the server. After receiving the request packet, the server sends an HTTP response packet to the browser.

2. HTTP / 1.0

HTTP/1.0 uses a non-continuous connection. In this mode, each time the browser requests a file, it establishes a TCP connection with the server and immediately closes the connection when it receives a response.

Corresponding disadvantages

  1. Twice the RTT cost per document requested. If a web page has many reference objects (such as images, etc.), it takes 2RTT to request each object
  2. To reduce latency, browsers typically establish parallel TCP connections to request multiple objects at the same time. However, this can take a lot of resources from the Web server, especiallyWeb servers tend to be overloaded with requests from a large number of customers simultaneously.

3. HTTP / 1.1

HTTP/1.1 uses persistent connection. In this way, the WEB server sends a response after sending a response to maintain the connection, so that the same client and the server can continue to send subsequent HTTP request and response messages on this link. This is not limited to passing objects on the same page, but as long as the documents are all on the same server.

  1. For further efficiency, HTTP/1.1 persistent connections can also be usedPipelined work.That is, the browser can send multiple HTTP requests in a row before receiving an HTTP response. After one request after another reaches the server, the server sends back one response after another.This saves a lot of RTT time, reduces idle time in the TCP connection, and improves the efficiency of downloading documents.

(5) HTTP packet format

HTTP is text-oriented. Each field of a message is an ASCII string, and the length of each field is uncertain.

1. HTTP request packets

  1. Request Line: Request line in an HTTP request packet consists of request method, URL, and Protocol Version, which are separated by Spaces. This part is essential. At the end of the request line, there is a carriage return control and a newline control (represented together as “CRLF”) to make the following request header information appear on the next line.

  2. Request header line: The HTTP request header consists of a series of “request headers” and their corresponding values, indicating that the client is allowed to pass additional information about the request to the server as well as information about the client itself. When a web page is opened, the browser sends an HTTP request header to the web server. The web server then generates the content of the current request and sends it to the browser. This is the function of the “request header” in the HTTP request packet.

  3. Empty line: An empty line after the last request header notifies the server that there are no more headers following the carriage return and newline characters;

  4. Entity body line: The “entity body” part of the request message is usually not used. It cannot be used in the GET method and is only used in the POST method to provide some user credential information to the server (usually not).

2. HTTP response packets

An HTTP response packet consists of a status line, a response header, a blank line, and an entity body.

  1. Status line: A status line consists of the HTTP version field, status code, and description of the status code. They are separated by Spaces.

  2. Response header: The response header provides the client with additional information, such as who is sending the response, the responder’s function, and even some special instructions related to the response. These headers help the client process the response and make better requests in the future. The response header fields include Age, Location, proxy-authenticate, Public, Retry-after, Server, Vary, Warning, and www-authenticate. The extension of response header fields requires the support of both communication parties. If an unsupported response header field exists, it is generally treated as an entity header field.

  3. Empty line: The last response header is followed by an empty line, which sends a carriage return and a newline to inform the server that there are no more response headers below.

  4. Entity body: Text information returned by the server to the client.

(6) Cookie

1. Cookie introduction

The early world Wide Web applications were very simple, just users looking at various static documents stored on different servers. HTTP is therefore designed to be a stateless protocol. This simplifies the server design.

Now, users can use the World Wide Web to achieve all kinds of complex applications, such as online shopping, e-commerce and so on. These applications often require web servers to be able to identify users.

Cookies provide a mechanism for web servers to “remember” users without the need for users to voluntarily provide user identity information. In other words, cookies are a technique for stateless HTTP to be stateful.

2. Use of cookies

User host accesses the World Wide Web server for the first time

When a TCP connection is established between the browser on a user’s machine and the World Wide Web server, port number is 80. At this time, the browser of the user host sends an HTTP request to the server, and the World Wide Web server generates a unique Cookie identification code for the client, and creates a project in the server’s back-end database based on this index, which is used to record the various information of the user visiting the website. Then, the Cookie is placed in the HTTP response packet, and the browser of the user host saves the Cookie to a file after receiving it.

The user host is not visiting the world Wide Web server for the first time

Not the first time when the user’s browser to access the web server, so the user has had the browser and the web server host established after the TCP connection, the user of the host to the HTTP server sends the web browser will carry the Cookie in the request, the world wide web server according to the identification of Cookie identification number can identify the user, And returns a personalized web page for the user. An HTTP response packet carrying a personalized web page is then sent to the browser in the user host.

(7) Web cache

The Web cache, also known as the Web cache, can be located on the client or in an intermediate system, which is also known as a proxy server.

The Web cache temporarily stores recent requests and responses to local disk. When a new request arrives, if it is found to be the same as the provisionated request, the provisionated response is returned without needing to go to the Internet again to access the resource at the URL.

If the Web cache hit ratio is high, the traffic on the link is greatly reduced, thus reducing the latency for accessing the Internet.

1. Resource request process with proxy server

The browser in the user host will send a request to the proxy server. If the proxy server holds the requested object, the corresponding object will be put back directly.

If the proxy server does not have the appropriate staging object, the proxy server sends the request to the original server, the original server receives the request and sends the response to the proxy server, which stores it internally and sends the corresponding response object to the user host.

2. The documents on the proxy server may be inconsistent with those on the original server

So document expired in the proxy server, proxy server will send the request of the corresponding to the original server (including last-modified field), the original server will compare to its, if the result is the same, that is to change the corresponding proxy server of documents in time, it is set to not expired, equivalent to activate it.

If an inconsistency is found, the original server sends a response message with the changed document, which the proxy server uses to replace the original.