Author: Pasca time: 2019/01/05
Preface: Part from the network, only for learning.Copy the code
[TOC]
First, computer network architecture
There are still three thousand avenues, and there are multiple network architectures to describe networks in multiple dimensions. They are the TCP/IP four-tier network model, the TCP/IP five-tier network model and the ISO seven-tier network model, which is well known. Of course, the goal of any model is to establish a standard that more people can use, just like our languages: Mandarin and English. At present, TCP/IP has become a universal language in the Internet, and it is necessary to learn and use the network.
In 1978, the International Organization for Standardization (ISO) proposed the Open Systems Interconnection Reference Model, known as the OSI seven-layer model. In addition, there are TCP/IP four layer model, TCP/IP five layer model.
- OSI architecture: conceptually clear & ideologically complete, but complex & impractical
- TCP/IP four-layer architecture: contains a series of network protocols that constitute the foundation of the Internet, is the core protocol of the Internet & is widely used in local area network and wide area network
- TCP/IP five-layer architecture: OSI and TCP/IP four-layer model fusion, open the application of more data link layer and physical layer, easy to learn and use
1. Physical layer
The physical layer is mainly the transmission of raw data, where possible errors are checked by the upper data link layer. Keep in mind here that there are two important network devices at the physical layer: Repeaters and hubs. The function of both is mainly to connect the signal amplification between clients,
2. Data link layer
The data link layer provides services to the network layer on the basis of the services provided by the physical layer. The most basic service of the data link layer is to reliably transmit the data from the network layer to the target computer network layer of adjacent nodes.
3. Network layer
The purpose of the network layer is to realize the transparent transmission of data between two end systems. The specific functions include addressing and routing, connection establishment, maintenance and termination, etc. It provides services that eliminate the need for the transport layer to understand data transfer and switching technologies in the network. For the understanding of the network layer, the key words are “path selection, routing and logical addressing”.
4. Transport layer
The task of the transport layer is to make the best use of network resources according to the characteristics of the communication subnet, provide the function of establishing, maintaining and canceling the transmission connection between the session layer of two end systems, and be responsible for end-to-end reliable data transmission. The network layer only transmits the packets from the source node to the destination node according to the network address, while the transport layer is responsible for transmitting the data reliably to the corresponding port.
5. The session layer
The session layer mainly uses the end-to-end services provided by the transport layer to provide value-added services to the presentation layer, and is responsible for establishing, managing and terminating the session process to achieve data synchronization.
6. Presentation layer
The presentation layer transforms the upper-layer data or information to ensure that information from one host application layer can be understood by applications from another host. The data transformation of presentation layer includes data encryption, compression, format transformation and so on.
7. Application layer
Provides an interface for an operating system or network application to access network services.
2. IP address (IPv4 address
1, define,
A globally unique identifier for each host (or router) connected to the Internet
Of 2,
IP address = 32 bits = Network number + Host NUMBER; IP address ={< network number >, < host number >}
Network number: indicates the network to which the host (or router) is connected. A network number must be unique throughout the Internet. Host number: Identifies the host (or router). The network range specified by the network number in front of a host number must be unique.Copy the code
Different TYPES of IP addresses have different host numbers and network numbers in bytes. Therefore, an IP address is unique across the entire network
3, classification,
Traditional IP addresses are classified into five types: A, B, C, D, and E
The difference lies in the number of bytes taken up by the network number and host numberCopy the code
4. Private address
The IPv4 address protocol reserves three IP address segments as private addresses for use within an organization (Intranet). Class A private address: 10.0.0.0/8 (range: 10.0.0.0 to 10.255.255.255) Class B Private address: 172.16.0.0/12 (range: 10.0.0.0 to 10.255.255.255) 172.16.0.0 to 172.31.255.255 Class C private address: 192.168.0.0/16. The value ranges from 192.168.0.0 to 192.168.255.255
Note that some IP addresses are used for special purposes and cannot be used as host IP addresses
TCP/UDP
1, the TCP
1.1 Definitions and Features,
Transmission Control Protocol.
- Connection-oriented, byte stream oriented, full duplex communication, reliable
1.2 the advantages and disadvantages
- Advantages: Reliable data transmission
- Disadvantages: Low efficiency (connections need to be established and confirmation packets sent
1.3 Format of Packet Segments
The first 20 characters of the TCP header are fixed, followed by 4N bytes. Therefore, the minimum length of the TCP header is 20 bytes
1.4 Link building – Three handshakes
Important: The need for a three-way handshake
-
Conclusion If the server receives invalid connection request packets, the server waits for requests from the client, resulting in deadlock and waste of resources
-
A detailed description
1.5 Release the connection – wave four times
At the end of the communication, both sides can release the connection, with a total of four waves of the hand
Important: The necessity of four waves
To ensure that both communication parties can notify each other of the need to release & disconnect, that is, neither party can receive or send messages to the other party after the connection is released
2, UDP
2.1 Definition and Features
The User Datagram Protocol is connectionless, unreliable, message-oriented, and without congestion control.
2.2 the advantages and disadvantages
- Advantages: Fast speed
- Disadvantages: Easy to lose messages (especially when the network is poor)
2.3 Format of packet Segments
- A UDP packet segment has two fields: data field and header field
- Here is the header (8 bytes, 4 fields)
3. Compare TCP and UDP
HTTP protocol
1, the introduction of
2. Working mode
The HTTP protocol works in request/response mode, as shown in the following figure.
3. HTTP structure introduction
1. Request line
Meaning: Declare the request method, host name, resource path & protocol version
Request line composition = request method + request path + protocol version
Key: Post and Get methods
Example:
GET/buckets HTTP / 1.1Copy the code
2. Request headers
- Function: Declare some information about the client, server, or packet
- Usage: Use the “header: value” format
- Common request headers
- Common headers for request and response messages
- Common request headers
The sample
Host: rs.qbox.me Content-type: Application/X-www-form-urlencoded user-agent: Mozilla/5.0Copy the code
3. Request body
- Function: Stores data to be sent to the server
Optional parts, such as GET requests, have no request dataCopy the code
There are three ways to use:
4, summarize
Example:
Five, the Socket
A Soclet is an intermediate software abstraction layer for the communication between the application layer and the TCP/IP protocol family. A Soclet is an API that encapsulates the TCP/IP protocol family.
Socket is not a protocol, but a programming call interface (API), belongs to the transport layer (mainly to solve the data transmission in the network), namely: Through Socket, we can develop on the Andorid platform through TCP/IP protocol. For users, only need to call Socket to organize data, in accordance with the specified protocol, can communicateCopy the code
- 2. To come in pairs or pairs of sockets:
Socket ={(IP address 1:PORT number), (IP address 2:PORT number)}Copy the code
- A Socket instance uniquely represents a communication link for an application on a host
Six, small knowledge
1. Differences between routers and switches
2. Cookies and sessions
-
Introduction to the
-
Difference & contrast
3. Cookies and Tokens
-
Introduction to the
-
Cookie-based authentication & authentication process
-
Token-based authentication & authentication process
4, browser open domain name process resolution
Open a web page and complete the process as follows: