1, the Application
(1) Common architecture of network application
Generally, network applications use two architecture modes: CS Client/Server architecture and PEER-to-peer architecture
For CS architecture, each node in the network is asymmetric, which can be divided into two types: server and client
Simply put, the server has resources to provide services for the client, and the client needs resources and applies for services from the server
For P2P architecture, every node in the network is symmetric, which can be said that every node is a server and a client
Because each node has resources, each node can provide services, and each node also needs resources, and each node also needs to apply for services
(2) Communication mode of network application
The communication between different applications is actually the communication between different processes. If two processes are running on the same host, the communication process is defined by the operating system
If two processes are not on the same host, the communication between them needs to be over the network, and the communication process is defined by a series of hierarchical network protocols
At the application level, we just need to define the content of the good news and specify who to send it to (the target process)
One process can deliver messages to the underlying layer through the socket, and then another process can get messages from the underlying layer through the socket through the services provided by the underlying layer
How does the underlying layer get messages from one socket to another
(3) How to locate the process
How to locate a process running on the network? We can locate the host on the network by IP address, and then locate the process on the host by port
Some common application layer protocols have default port numbers:
agreement | port | use |
---|---|---|
HTTP | 80 | Web transmission |
FTP | 21 | The file transfer |
SMTP | 25 | Mail delivery |
POP3 | 110 | Receive emails |
IMAP | 143 | Receive emails |
Telnet | 23 | Remote login |
Web and HTTP
(1) Communication process
For Web applications, Hypertext Transfer Protocol (HTTP) is usually used to control communication rules, which depends on the services provided by TCP
According to the standards, HTTP protocols can be divided into HTTP/1.0 and HTTP/1.1, which is an improvement of HTTP/1.0
In HTTP/1.0, non-persistent Connection is used. For CS architecture, the communication process is as follows:
- The client requests to establish a TCP connection with the server
- The server agrees to establish a TCP connection
- The client sends a request specifying the resource to be obtained in the request information
- The server returns a response, including the resource entity in the response information, and then closes the TCP connection
- The client receives the response and retrieves the resource entity
- Repeat the above steps if you find that the resource entity also references other resources
However, in HTTP/1.1, Persistent Connection is used. For CS architecture, the communication process is as follows:
- The client requests to establish a TCP connection with the server
- The server agrees to establish a TCP connection
- The client sends a request specifying the resource to be obtained in the request information
- The server returns the response, including the resource entity in the response information, but does not close the TCP connection
- The client receives the response and retrieves the resource entity
- Repeat steps 3 to 5 if you find a resource entity that also references other resources
Suppose we need to transfer an HTML file, reference ten JEPG images in the file, and calculate the transfer time?
- For non-continuous connection: T = (2RTT + Ttransfer) + (2RTT + Ttransfer) * 10
- If continuous connection is used: T = (2RTT + Ttransfer) + (RTT + Ttransfer) * 10
(2) Message format
HTTP adopts the Request/Response format. The client submits a Request and the server returns a Response.
The format of the request message is shown below. Common request methods are as follows:
- GET: Requests the specified resource and returns the resource entity
- POST: Submits data to a specified resource, which may result in the creation of new resources or the modification of old resources
- HEAD: Similar to a GET request, but returns a response with no concrete content. It is often used to retrieve headers
- DELETE: deletes the specified resource
- PUT: Replaces a specified resource with submitted data
- TRACE: Returns the request received by the server, often used for testing
- OPTIONS: Returns the request methods supported by the server for a specific resource. It can also be used to view the performance of the server
What’s the difference between GET and POST?
1. Different functions of conventions. GET is used to query data from the server, and POST is used to modify data on the server
2, the location of parameters is different (browser implementation), GET request parameters in the URL, POST request parameters in the Body
The size of parameters for GET requests may be limited because browsers may have restrictions on the length of urls
The parameters of a GET request are retained in the browser’s history, but the parameters of a POST request are not
GET requests are idempotent and have no side effects, whereas POST requests are not idempotent and have side effects
When you hit the back button or refresh the page, GET doesn’t have any effect; POST resubmits the request
The result of a GET request can be used as a browser bookmark, but a POST request cannot
The results of GET requests are actively cached by the browser, but POST requests are not
The format of the response message is shown in the picture below, where the common status code and status information are as follows:
-
1** : message. The server receives a request asking the client to continue the operation
-
2 * * : success
- 200: OK, the server successfully processed the request and returned the requested resource
-
3** : redirects
- 301: Moved Permanently, Permanently redirected, the requested resource Permanently Moved to a new location
- 302: Moved Temporarily, redirect the requested resource to a new location
-
4** : Client error
- 400: Bad Request: Syntax errors exist in the Request packet
- 403: Forbidden, access to requested resources is denied by the server
- 404: Not Found, requested resource Not Found on server
-
5** : The server is faulty
- 500: Internal Server Error. An Error occurs when the Server executes a request
- 502: Bad Gateway, the server acting as the Gateway received an invalid response from the remote server while executing the request
- 503: Service Unavailable indicates that the server is temporarily unable to process requests from clients due to server overload or downtime for maintenance
What’s the difference between 301 and 302?
They are redirected, meaning that the browser automatically redirects to a new address when it gets 301 or 302
Then there are the differences:
301 indicates that resources at the old address are removed permanently. When searching for new content, the search engine replaces the old address with the new address
302 indicates that the resource of the old address is still in fact, but only temporarily jumps to the new address. The search engine will grab the new content, but keep the old address
(3) the Cookies
Since the HTTP protocol is stateless, the server can use Cookies to track the user’s state
A Cookie is simply a special value that is created and maintained by the server and sent to the client
After that, the client brings a Cookie with each request, and the server can judge the user’s status through the Cookie
(4) Caches
Caches technology reduces the time it takes to get a response from the client, and reduces the pressure on the server to handle requests, so you can kill two birds with one stone
To use Caches is to set up one or more proxy servers that help respond to client requests
The client sends the request directly to the proxy server, and if the requested resource is on the proxy server, it is returned directly to the client
If not, the proxy server requests resources from the server, gets them, stores them locally, and returns them to the client
A brief description of the development of the HTTP protocol?
HTTP/0.9 [1991 年]
- The simplest version can only access resources in HTML format, with no headers and only GET requests
HTTP/1.0 [1996 年]
- Example Add the HTTP version number
- Add status code and status information
- Add request methods, including POST and HEAD
- Add headers for both requests and responses
- Other types of files can be transferred by setting the content-type in the header
HTTP/1.1 [1997 年]
- Adding persistent connections enables HTTP requests to reuse TCP connections
- Pipelined transport is supported, allowing multiple requests to be sent simultaneously in a SINGLE TCP connection
- Add request methods, including DELETE, PUT, OPTIONS, and so on
HTTP/2.0 [2015 年]
- Binary framing: The partitioning of transmitted data into smaller frames and binary encoding of them
- Server push: Allows the client to send resources to the client without request
- Compression header: many requests for many headers are actually repeated, it is necessary to deal with the header is to use compression tools to compress the header and then send, the second is to repeat the field can use the index number to replace
File and FTP
(1) Communication process
File Transfer Protocol (FTP) is used to control the communication rules for File Transfer, which depends on the services provided by TCP
The FTP protocol establishes two connections in communication, namely a Control Connection and a Data Connection.
- Control connection: Used to transmit commands for authentication
- Data connection: Used to transfer files
For CS architecture, the communication process is as follows:
- The client establishes a control connection with the server
- The client authorizes and sends commands by controlling the connection
- After receiving the file transfer command, the server establishes a data connection
- The server transfers files over a data connection. When a file is transferred, the server closes the data connection
- If there are other file transfers, the data connection needs to be re-established
(2) Message format
FTP uses the command/response format. The commands sent by the client and the responses returned by the server are transmitted over the control connection. They are both 7-bit ASCII
The client sends commands to authorize and request resources. The common commands are as follows:
USER username
: Sends the account to the serverPASS password
: Sends the password to the serverLIST
: Returns a list of files in the current directoryRETR filename
: Downloads files from the serverSTOR filename
: Uploads the file to the server
After receiving the command, the server sends a Response to return the result. A Response includes a status code and status information. Common responses are as follows:
311
: If the account is correct, the password is required125
: A data connection has been established and files are being transferred425
: The data connection cannot be established
4. Email and SMTP
(1) Communication process
For Mail transmission, Simple Mail Transfer Protocol (SMTP) is used to control communication rules, which depends on the services provided by TCP
There are two important components of Mail transmission, namely User Agent and Mail Server.
- User agent: Used to edit and read mail
- Mail server: Used to send and receive mails
For CS architecture, the communication process is as follows:
- The sender edits the message through its own user agent
- The sender’s user agent sends messages to its own mail server
- The sender’s mail server receives the Message, places it in a Message Queue, and waits for it to be sent
- The sender’s mail server sends mail messages to the receiver’s mail server
- The recipient’s Mail server receives the message, puts it in a Mail Box, and waits for it to be read
- The recipient reads the message through its own user agent
(2) Message format
In the beginning, mail could only transmit text, so simple ASCII was used to define the mail format
The regular mail format consists of two parts, Header and Body.
Later, Mail can also transmit multimedia resources, and a new format MIME (Multiperpose Internet Mail Extension) was defined.
Just add a new line in the header specifying that the MIME mail format is used
SMTP also uses the command/response format. The commands sent by the client and the responses returned by the server are 7 bits ASCII
The client sends commands to authorize and request resources. The common commands are as follows:
HELO
: Establish a connectionAUTH LOGIN
: Identity authenticationMAIL FROM address
: Specifies the mailbox from which mails are sentRCPT TO address
: Specifies the mailbox to receive the mailDATA
: Specifies the email bodyQUIT
: Close the connection
After receiving the command, the server sends a Response to return the result. A Response includes a status code and status information. Common responses are as follows:
220
: Service ready250
: Required operation completed354
: Starts to enter the message body to.
The end of the221
: Service shutdown
(3) Other mail protocols
SMTP is the mail sending protocol. POP3 and IMAP are the mail receiving protocols
- Post Office Protocol 3 (POP3) : allows users to download mails from the mail server
- Internet Mail Access Protocol (IMAP) : allows users to directly manage mails on the Mail server, including Mail movement and Mail classification
5, DNS
The Domain Name System (DNS) resolves a Domain Name into an IP address
DNS is a distributed, hierarchical database, which stores the mapping between domain names and IP addresses, called Resource Records.
The format of a resource record is as follows: Name, value, type, TTL. Common resource records are as follows:
- A Record: If type is A, name indicates the domain name and value indicates the IP address
- NS record: If type is NS, name indicates the domain name, and value indicates the domain name of the DNS server that parses the name
- SOA record: When type is SET to SOA, name indicates the domain name and value indicates the domain name of the primary DNS server that parses name
- CNAME record: When type is CNAME, name indicates an alias and value indicates a standard name
The database can be divided into four layers according to different levels:
- Root DNS Server: There are 13 Root DNS servers in the world
- Top-level Domain DNS Server: provides top-level Domain name resolution services such as com, org, net, and edu
- Authoritative DNS Server: Provides resolution services for certain organizations
- Local DNS Server: strictly speaking, it does not belong to layer 1. Each ISP has a Local DNS Server
DNS is also an application-layer protocol. When requesting domain name resolution services, DNS is used to control communication rules, which relies on UDP services
(1) Communication process
When a client requests DNS service from the DNS server, there are two query methods: iterative query and recursive query
If an Iterated Query is used, the communication is as follows:
If Recursive Query is used, the communication process is as follows:
(2) Message format
DNS uses the request/reply format, which uses the same message