9.3.1 Network principle (application layer)

The blog behind HTTP and HTTPS will introduce it separately. 

1. Design the application layer protocol:

1. Clarify what is included in the current request and response.

2. Clarify the specific request and response format.

The data transmitted on the network is essentially a string (objects cannot be directly transmitted).

Serial number: When sending data, convert the object into a binary string. (Note that the data transmitted on the network is unified into big-endian byte order)

Deserialization: When receiving data, convert binary strings into objects.

3. The client and server must use the same set of protocols.

2. General agreement:

1.xml: Key-value pair information is represented by paired tags, and tags support nesting, which can represent some complex tree-structured data.

Advantages: Very clear representation of structured data.

Disadvantages: Introducing a large number of tags looks cumbersome and takes up a lot of network bandwidth.

In China, the most expensive network resource is bandwidth. 

2.json (currently the most mainstream and commonly used): it is essentially a key-value pair, which is more concise than xml.

In json, braces are used to represent key-value pairs, and square brackets are used to represent arrays. Each element in the array can be a number, a string, or braces and square brackets.

 During network transmission, it will compress (remove unnecessary newlines and spaces), and put all data into one line (reduces bandwidth, but affects readability, but there are ready-made formatting tools for easy reading).

3.protobuffer: The binary data serial number method proposed by Google.

Use the binary method to agree on which attribute a certain number of bytes represent, which can save space to the greatest extent (there is no need to transmit the key, and the attribute is distinguished according to the position and length).

Advantages: maximize bandwidth savings and high efficiency.

Disadvantages: Binary data cannot be observed by the naked eye, and it is inconvenient to debug.

Guess you like

Origin blog.csdn.net/m0_73345579/article/details/132244121