Computer Fundamentals
1.TCP three-way handshake
First handshake: (client: tell server: I want to connect with you) The client sends a packet with bit code SYN=1, randomly generating seq number=1234567 to the server. The server knows from SYN=1 that the client wants to establish an online connection. Ack number=(client seQ +1), SYN =1, ACK =1, and seQ =7654321 After verification, send data to the server.) After receiving the packet, the client checks whether the ACK number is correct, that is, the SEQ number+1 sent for the first time and the bit code ACK is 1. If yes, the client sends ack number=(seQ +1 of the server), ACK =1. If the server receives the seQ value and ACK =1, the connection is established successfully.Copy the code
2. Why does HTTP require three handshakes to establish a connection, not two or four?
Answer: three times is the least safe number, two times is not safe, four times waste resources;
3.TCP closes the connection
1. The Client requests to close the connection: (Tells the Server: I am about to close the connection. Have you finished sending the packet?) The Client sends a FIN packet to the Server to close the connection and enters the FIN_WAIT_1 state, waiting for the Server to return the ACK packet. The Client can no longer send data to the Server, but can read data. After receiving the FIN packet, the Server sends the ACK packet to the Client and enters CLOSE_WAIT state. After that, the Server cannot read data but can continue to send data to the Client. 3. The Client receives the received data message :(I know, I close the ACK packet and send the data immediately.) after receiving the ACK packet from the Server, the Client enters the FIN_WAIT_2 state and waits for the Server to send the FIN packet. After sending data, the Server sends the FIN packet to the Client and then enters the LAST_ACK state. After that, the Server cannot read or send data. 5. The client receives the last data (after receiving the last data, the client tells the server: I have received the final data, please close yourself as soon as possible, I will wait for you for 2ms, I will also close myself, do not need to reply me.) After receiving the FIN packet, the Client sends the ACK packet to the Server, and then enters the TIME_WAIT state. It then waits for enough time (2MSL) to ensure that the Server receives the ACK packet, and finally returns to the CLOSED state to release network resources. 6. The Server enters the CLOSED state after knowing that the Client has received the data. After receiving the ACK packet from the Client, the Server returns to the CLOSED state to release network resources.Copy the code
4. Why wave four times?
TCP is a full-duplex channel. Two channels are established between the client and the server. Channel 1: The output of the client connects to the input of the server. Channel 2: Client input connects server output. Both channels work simultaneously: the client sends signals to the server at the same time that the server sends signals to the client. Client: I'm going to close the input channel. Server: Ok, you close it and I will close the channel on my side. Server: I'm also going to close the input channel. Client: Ok, you close it. I'll close this channel too.Copy the code
5. Wave four times
Fourth Wave (1) First wave: The Client sends the FIN flag to the Server to disable data transmission from the Client to the Server and sends the sequence number A to enter the FIN_WAIT_1 state. This means that the Client tells the Server that I have no more data to send to you. (2) Second wave: After receiving the FIN flag, the Server sends an ACK =a+1 to inform the Client that it has received the close request and enters CLOSE_WAIT state. Clinet receives the response and enters the FIN_WAIT_2 state. (3) Third wave: The Server sends the FIN flag to disable data transmission from the Server to the Client and sends the sequence number B to enter the LAST_ACK state. This means that the Server tells the Client that I have no data to send to you either. (4) Fourth wave: After receiving the FIN flag, the Client sends an ACK = B +1 to inform the Server that it has received the request to close and enters the TIME_WAIT state. The Server enters the CLOSED state after receiving the response. After waiting for 2MSL, if the Client still receives no other reply, it will also enter CLOSED.Copy the code
6. The CDN? Introduction method?
What is CDN? Why is CDN introduction needed? What are the advantages over a traditional NPM installation?
7. Processes, threads (Chrome multi-threaded browser)
Single-threaded: Tasks are executed sequentially, one by one
Multithreading: Multitasking (too many people can do things fast, but you need a stable and sound management system, otherwise it’s easy to mess up)
The relationship between processes and threads
Threads can not exist alone, it is started and managed by the process, a process is a running instance of a program, with multiple threads to run the program. Thread is attached to process, and using multi-thread parallel processing in process can improve computing efficiency. Threads share data in a process. When a process is shut down, the operating system reclaims the memory occupied by the process.Copy the code
8. Five layer model of computer network
Easy to understand
Physical layer: optical fiber connects two computers to realize communication (data transmission by electrical signal 01)
Data link layer: Specification of data transmission form (‘ frame ‘transmission)
Ethernet protocol: // Specify the type of data to be sent: HEAD + DATA table header HEAD: used to store sender information for identification Table body DATA: data to be transmitted // Specify the identification identifier of two computers: MAC address (each computer has a unique identifier: Id card (physical address of computer) why can A send to B when broadcasting with subnet: because you know its MAC address, so you can send to BCopy the code
Network layer: determine whether it belongs to a subnet by IP address, accurately find the corresponding computer (establish host-to-host communication)
// Exact transmission path of data Computer A-- Computer B: optical fiber application A-- Application B: IP address and port // Data transmission mode: broadcast with subnet: Computer A broadcasts packet A to all computers in A subnet. The BCD of other computers receives the packet and resolves whether it was sent to them or not. If not, the packet is discarded. Different subnet: Computer A sends packet A to the gateway and then the gateway forwards the packet to othersCopy the code
Transport layer: establishes port-to-port communication (data consumer identification)
9. Same-origin policy and cross-domain
// If the protocol, domain name, and port of two pages are the same, the two pages have the same source
What is the same origin policy a security feature provided by browsers
What it does: Limits resource interaction between two non-homologous sites (no DOM reading across domains, no Ajax requests, etc.)
Web page A sends A cross-domain request to web page B. Web page B can receive the request, and the data returned to web page A must pass the same origin policy set by the browser. The browser detects that you are in A cross-domain behavior and does not allow you to return data to web page A = Intercept
Cross-domain implementation: JSONP
- Implementation principle:
The <script> tag, independent of the same origin policy, requests a cross-domain data interface through the SCR attribute and receives the data back in response as a function callCopy the code
2. Disadvantages:
Only GET requests are supportedCopy the code
10. The IP address? Subnet mask?
//IP address composition: network part + host part '192.168.43.1' (but you do not know if it is a subnet) If the MAC addresses of two computers are in the same subnet // How to determine whether the MAC addresses of two computers are in the same subnet: If the IP addresses of some computers are in the same subnet, the IP addresses of some computers are in the same subnet. // The function of the subnet mask is to resolve the network part and the host part (determine the first few bits are the network part and the last few bits are the host part).Copy the code
11. The port?
Function: Determines the data user (application) in the transport layer. The data has been sent to our computer, but to which application is not specified. Thus, there is a port. Each program on the computer occupies a port. The port number will be identified in the data transfer layer protocol, so as to accurately transfer data to the corresponding client.
12. Interface API?
Interface user: An abstraction of "dependencies" on the outside world, indicating which capabilities it depends on; (I will use the wrench tool to turn the screw (call the interface of a specific function to achieve their own needs) interface implementer: the abstraction of their own "ability", declare that they have what ability. Encapsulate your ability (function) in a name: wrench, call wrench is using my ability) 1. Data interface: Get data of book list page: use URL data interface, call URL: HTTP: / / www.book.com/api/getbookslist interface to get the data (data packages for package, the package for a mouth, the mouth is interface, call/send data out from the mouth, don't call interface you will not be able to obtain the data inside) 2. Component interface: Decouple the component structure and content. The parent component calls the child component (interface), and the child component can be used for presentation. (Interface advantage: The parent component only needs to care about calling the child component to implement the function, not how the child component implements the function)Copy the code
13. The HTTP protocol
What is the HTTP protocol?
HTTP fully explain
What is?
// TCP/ IP-based protocol for how data is communicated on the World Wide WebCopy the code
Function:
HTTP protocol is the format of letter writing. If you follow this format, you can recognize each other to realize the transmission of web content between the client and server. Both sides must comply with the transmission protocol of web contentCopy the code
Format :(request message)
HTTP request packets are divided into three parts: the request line, the request header, and the request body (GET does not have the request body, and POST does have the request body).Copy the code
Request header:
HTTP response packet
HTTP response packets are divided into three parts: response status line, response header, and response body
Response: Response Header
Request: Request Header
Status code
Status codeUsed to identify the response status
Common status code
2 xx success
200 OK: indicates that the request sent from the client is correctly processed on the server. 204 No Content: indicates that the request is successful, but the response packet does not contain the body part of the entityCopy the code
3 xx redirection
301 Moved permanently, permanently redirects permanently, indicating that the resource has been assigned a new URL 302 found, temporarily redirects permanently, indicating that the resource has been assigned a new URL 303 see other 304 Not Modified indicates that the server allows access to the resource, but the request condition is not metCopy the code
4XX Client error
401 Unauthorized requests require HTTP authentication information. 403 Forbidden The access to the requested resources is denied by the server. 404 Not Found The requested resource was not found on the serverCopy the code
5XX Server error
500 Internal sever Error: 503 Service Unavailable Indicates that the server is temporarily overloaded or is being stopped for maintenance and cannot process requestsCopy the code
14. Resource request method: Get and POST difference
What is?
What are get and post? Two methods of sending a request in HTTPCopy the code
Behavior:
Get request: requests resources from the server. Post request: sends (submits) resources to the serverCopy the code
Usage Scenarios:
Get Application scenario: 1. Requests resources such as text data and IMG data from the server based on the URL address. Send password to the server upon login Account Information Resource 2. Add user information (during user comment) and submit the user information to the serverCopy the code
Superficial differences:
GET
The data of the GET request is appended to the URL using? Split, multiple parameters are connected with &. The data from the GET request is exposed in the address bar. GET request urls are encoded in ASCII rather than Unicode. The transfer size of GET requests is limited to 2KB. Random theory (URL can always add data request, but you add too much, for the worse performance of server/browser can create analytic difficulty, so general browser limit your data in 2 KB size, most of the servers can parse size limit in 64 KB) (server because handle long URL consumes more resources, URL length is limited for performance and security reasons (to prevent malicious construction of long urls for attacks). GET is insecure and will be actively cached by the browser. (Superficial security: Wouldn't you be concerned if your password and account were stored in a web address that people could see directly?) (Essential security: the security is the same, because they are essentially TCP, the same transport layer, and HTTP is plaintext transmission, unencrypted, so get and POST can be seen, post is just put data in a folder, you just open the folder and still see the data. GET generates a TCP packet, head and data are sent together. (Identify the head and data body data) GET The browser rollback is harmlessCopy the code
POST
A POST request places the data in the body of the HTTP request package and is not directly exposed to the user. (Create a file, put the data in it, send the file to the server) POST requests. In theory, there is no limit on the size of POST requests, but in practice, each server will specify the size of the data submitted by POST. POST is more secure than Get because the parameter is not stored in browser vertical or Web server logs. POST generates two TCP packets, the header is sent, the server responds with 100 and continues, sending data, the server responds with 200 and returns data. (The HTTP protocol also doesn't explicitly say that POST produces two TCP packets, and actual testing (Chrome) found that Header and Body are not sent separately. Therefore, sending headers and Body separately is a partial browser or framework request method, not necessarily a Post behavior. POST Indicates that the browser rolls back the request again.Copy the code
Essential difference: no difference
GET and POST are only two HTTP request modes. HTTP is an application layer protocol based on TCP/IP. Both GET and POST use the same transport layer protocol, so there is no difference in transmission.Copy the code
15. Client and server
It’s two computers for different purposes
2. Server: external responsible for storing/providing resources of the computer, known as the server (server is a computer in nature, but the performance is very high, used to store and send a large amount of data) (resources storage place) 3. Client: The computer responsible for obtaining/consuming resources, called the client (the place to obtain resources) (usually using a browser to browse and obtain resources)Copy the code
16. Url components
The process by which a client communicates with a server
Server sends resource = Server responds