当前位置:网站首页>"Renegotiation" agreement
"Renegotiation" agreement
2022-06-26 03:39:00 【The Keystroker of Shubi Lake】
List of articles
Agreement is a kind of agreement , But for socket api The data in the socket is transmitted through strings , So if we want to transfer in a structured data , How to operate it ?
Online calculator
If we want to specify a calculator , Then the client should send two data and an operation symbol to the server , The server will send the final data to the client after analysis and calculation .
for example : We need to specify an adder , Then the client should send two data and one to the server “+” Symbol , So for the server , He must have one of his own agreement , This agreement is the agreed plan , It is agreed that when the client requests the server , How data should be sent , How the data will eventually be returned , Only such operations , The client can get the results that customers want .
Agreed scheme
for example : We're going to make an adder , Then we should have the following agreement
Appointment one :
- The data sent is in order , And an addition operator between two numbers . for example :“1+2”.
- The data sent must be an integer , Operator must be +.
- There are no spaces between numbers and operators .
Agreement II :
- The data sent does not need to be sent in sequence , Use the structure to package .
- The data sent must be an integer , Operator must be +.
It's just a part of the agreement , Because we don't need many conventions to implement an adder .
Be careful : Whether it is agreement one or agreement two , Their ultimate goal is to create a unified event ( For one thing ), That is to let the customer send something , The server can know how to correctly handle the incoming data ( That is, the server can correctly parse ).
Simple implementation of addition server
For the implementation of adder , We use a structure to send data , Because for the structure , It can separate data from operators , It makes it very easy to parse data and operators .
Encapsulates a socket class for an addition server , as follows :
The server implementation is as follows :
The implementation of the client is as follows :
Can see , During the transmission of information , Using a structure , Because the structure can directly separate the data and symbols we want to transfer , It can make the server better to parse , This is what serialization and deserialization do .
Serialization and deserialization
Above we mentioned serialization and deserialization , So what exactly do they mean ?
1. serialize : The process of converting an object into a sequence of bytes .
2. Deserialization : The process of restoring a sequence of bytes to objects .
To put it bluntly , Serialization and deserialization are just like a rule , The server can receive data , And correctly analyze these data , But they also have some important functions :
- serialize : Organize multiple objects in a specified format into binary data strings that can be stored persistently or transmitted .( Ensure the integrity of the object , The ordered byte stream is used to prevent transmission on the network or storage in local files )
- Deserialization : The binary data string , Multiple data objects can be parsed according to the specified format .
Be careful : For serialized forms , He has a consideration
- Transmission performance : The serialized binary data string should be as short as possible .
- Analytical performance : The simpler the process of serialization and deserialization, the better .
Above we use the structure , Because according to the structural characteristics of the structure , The assignment of member variables can realize the organization of data in memory . But he has shortcomings , Because for different platforms , The use of bit segments may be inconsistent , Byte alignment may also be inconsistent .
3. Advantages of serialization :
- Keep objects permanently : The objects are stored on the hard disk in the form of binary sequence , It can not only reduce the space , And even when the virtual machine is interrupted for some reason , The sequence on the hard disk will not be affected , After the next boot, the object can still be parsed according to deserialization .
- Objects serialized as byte streams can be transmitted over the network .
- Objects can be passed between processes through serialization .
边栏推荐
猜你喜欢
Types and application methods of screen printing
如何筹备一场感人的婚礼
HL7Exception: Can‘t XML-encode a GenericMessage. Message must have a recognized struct
Qixia fire department carries out fire safety training on construction site
MySQL addition, deletion, query and modification (Advanced)
How Inkscape converts PNG pictures to SVG pictures without distortion
Run multiple main functions in the clion project
经典模型——ResNet
Multimedia elements, audio, video
You cannot call Glide. get() in registerComponents(), use the provided Glide instance instead
随机推荐
The role of children's programming in promoting traditional disciplines in China
QT compilation error: unknown module (s) in qt: script
kitti2bag 安装出现的各种错误
Is it safe for individuals to buy stocks with flush software? How to buy stocks
Hardware creation principle of campus maker space
论文回顾:Unmixing-Based Soft Color Segmentation for Image Manipulation
如何筹备一场感人的婚礼
Do you want to add a key to the applet or for sequence?
[QT] custom control - switch
点击事件
Some mobile phones open USB debugging, and the solution to installation failure
View of MySQL
显卡、GPU、CPU、CUDA、显存、RTX/GTX及查看方式
HL7Exception: Can‘t XML-encode a GenericMessage. Message must have a recognized struct
进程之间的通信方式
Request object, send request
GStreamer allocator and pool
MySQL增删查改(初阶)
Preparation for wechat applet development
Graphics card, GPU, CPU, CUDA, video memory, rtx/gtx and viewing mode