[Graphic network protocol] Interviewer: I can't shake hands three times, go back and wait for the notice

First, network basic knowledge preparation

insert image description here

1. Summary of OSI seven-layer network model:

  • The upper three layers (session layer, presentation layer and application layer) mainly provide information and data processing functions between users and applications.
  • Layer 4, as a bridge between the upper and lower parts, is the most critical part of the entire network architecture
  • The following 4 layers (physical layer, data link layer, network layer and transport layer) mainly provide data transmission and switching functions, that is, the communication between nodes is mainly based on

2. Summary of TCP/IP protocol:

  • Application layer: The layer for communication between applications, such as Simple Email Transfer (SMTP), File Transfer Protocol (FTP), Network Remote Access Protocol (Telnet), etc.
  • Transport layer: In this layer, it provides data transmission services between nodes, such as Transmission Control Protocol (TCP), User Data Reporting Protocol (UDP), etc. TCP and UDP add transmission data to data packets and transmit it to the next layer. Within a layer, this layer is responsible for delivering data and making sure that data has been delivered and received.
  • Network interconnection layer: Responsible for providing basic data packet transmission functions, so that each data packet can reach the destination host (but does not check whether it is received correctly), such as Internet Protocol (IP).
  • Host to network layer: Management of the actual network media, defining how to use the actual network (such as Ethernet, Serial Line, etc.) to transmit data.

3. TCP protocol process:

  • TCP (Transmission Control Protocol, Transmission Control Protocol) is a connection-oriented protocol, that is, when sending and receiving data, it is necessary to establish a reliable link with the opposite side. This is also the three-way handshake of TCP and the four-way wave of TCP that are often asked in interviews!
    • Three-way handshake: When establishing a TCP connection, the client and the server need to send a total of 3 packets to confirm the establishment of the connection. In Socket programming, this process is triggered by the client executing connect. The specific flow chart is as follows
      insert image description here

    • Wave four times: Terminating a TCP connection means that when a TCP connection is disconnected, the client and the server need to send a total of 4 packets to confirm the disconnection of the connection. In Socket programming, this process is triggered by either the client or the server executing close. The specific flow chart is as follows:
      insert image description here

    • Why is it a three-way handshake to establish a connection, but a four-way wave to close the connection?
      Because the server is in the LISTEN state, after receiving the SYN message for the connection establishment request, it puts the ACK and SYN in one message and sends it to the client. When closing the connection, when receiving the FIN message from the other party, it only means that the other party no longer sends data but can still receive data, and not all data is sent to the other party, so the party can immediately close or send some data. After the data is sent to the other party, the FIN message is sent to the other party to express the agreement to close the connection now. Therefore, the own ACK and FIN are generally sent separately.

4. UDP protocol:

  • UDP (User Datagram Protocol) User Datagram Protocol, a non-connection protocol, the source and terminal do not establish a connection before transmitting data. When it wants to transmit, it simply grabs the data from the application and sends it as quickly as possible. It's thrown on the web. On the sending end, the speed at which UDP transmits data is only limited by the speed at which the application generates data, the capabilities of the computer, and the transmission bandwidth; on the receiving end, UDP places each message segment in a queue, and the application removes each message from the queue each time. Read a message segment. Compared with TCP, there is no need to establish a link, the structure is simple, the correctness cannot be guaranteed, and it is easy to lose packets

5. What is socket

  • Socket is an abstraction layer between the application layer and the transport layer. It abstracts the complex operation of the TCP/IP layer into several simple interfaces for the application layer to call to realize the process communication in the network.
    insert image description here

  • Socket communication model:
    insert image description here

  • Socket communication implementation steps analysis:
    1: Create ServerSocket and Socket
    2: Open the input/output stream of the connected Socket
    3: Read/write the Socket according to the protocol
    4: Close the input and output stream, and the Socket

2. http protocol

1. What is the http protocol

  • The hypertext transfer protocol (Hypertext Transfer Protocol), an application layer protocol of the TCP/IP protocol, is used to define the process of exchanging data between a WEB browser and a WEB server. After the client connects to the web server, if it wants to obtain a certain web resource in the web server, it needs to comply with a certain communication format. The HTTP protocol is used to define the communication format between the client and the web server.

2. The difference between http 1.0 and http 1.1

  • 1.0 protocol, after the client establishes a connection with the web server, only one web resource can be obtained! The 1.1 protocol allows the client to obtain multiple web resources on one connection after establishing a connection with the web server!

3. The underlying workflow of the Http protocol:

  • understand two nouns

    • SYN (synchronous): The handshake signal used by TCP/IP to establish a connection
    • ACK (Acknowledgement): Confirmation character, confirming that the sent data has been accepted without error
  • The concept of TCP/IP three-way handshake:

    • The client sends a syn packet (syn = j) to the server, enters the SYN_SEND state, and then waits for the server to confirm
    • The server receives the syn packet, confirms the client's syn (ack = j + 1), and at the same time sends a SYN packet (syn=k), that is, the SYN + ACK packet, the server enters the SYN_RECV state
    • The client receives the SYN + ACK packet and sends an acknowledgment packet ACK (ack = k +1) to the server. After the transmission is completed, the client and the server enter the ESTABLISHED state, complete the three-way handshake, and then start to transmit data.
      insert image description here
  • http operation process:

    • The user clicks the url (hyperlink) on the browser, and the web browser establishes a connection with the web server
    • After the connection is established, the client sends a request to the server. The format of the request is: Uniform Resource Identifier (URL) + protocol version number (usually 1.1) + MIME information (multiple message headers) + a blank line
    • After the server receives the request, it gives the corresponding return information. The return format is: protocol version number + status line (processing result) + multiple information headers + blank line + entity content (such as returned HTML)
    • The client receives the information returned by the server, displays it through the browser, and then disconnects from the server; of course, if an error occurs at a certain step in the middle, the error information will be returned to the client and displayed, such as: the classic 404 error!

4. The business process of the http protocol

insert image description here

5. Comparison of http-get request and post request

  • GET: Bring the data to the server in the form of ? after the requested URL address, and separate multiple data with &, but the data capacity usually cannot exceed 2K, for example: http://xxx?username=…&pawd =...this is GET
  • POST: This can send data to the server in the requested entity content, there is no limit to the number of transfers
  • The security of GET is very low, and the security of Post is high, but the execution efficiency is better than that of Post method. We use GET for general queries, and POST for data addition, deletion and modification! !

6, the characteristics of the http protocol

  • 1. Support client/server mode.
  • 2. Simple and fast: When a client requests a service from the server, it only needs to transmit the request method and path. Commonly used request methods are GET, HEAD, and POST. Each method specifies a different type of contact between the client and the server. Because the HTTP protocol is simple, the program scale of the HTTP server is small, so the communication speed is fast.
  • 3. Flexible: HTTP allows the transmission of any type of data object. The type being transferred is marked by Content-Type.
  • 4. Connectionless: The meaning of connectionless is to limit processing to only one request per connection. After the server processes the client's request and receives the client's response, it disconnects the connection. In this way, transmission time can be saved.
  • 5. Stateless: The HTTP protocol is a stateless protocol. Stateless means that the protocol has no memory capability for transaction processing. The lack of state means that if previous information is required for subsequent processing, it must be retransmitted, potentially resulting in an increased amount of data transferred per connection. On the other hand, the server responds faster when it does not need the previous information.

3. https protocol

1. What is the https protocol

  • (Hypertext Transfer Protocol Secure: Hypertext Transfer Protocol Secure) is a transfer protocol for secure communication over computer networks. HTTPS communicates via HTTP, but utilizes SSL/TLS to encrypt packets. The main purpose of HTTPS development is to provide identity authentication for website servers and protect the privacy and integrity of exchanged data.

2. How https works

insert image description here

Guess you like

Origin blog.csdn.net/yuan2019035055/article/details/122310503