当前位置:网站首页>"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 .
边栏推荐
- Xgboost, lightgbm, catboost -- try to stand on the shoulders of giants
- 在哪里开基金帐户安全?
- 如何筹备一场感人的婚礼
- Solve the problem that the input box is blocked by the pop-up keyboard under the WebView transparent status bar
- [hash table] a very simple zipper hash structure, so that the effect is too poor, there are too many conflicts, and the linked list is too long
- 培育项目式Steam教育理念下的儿童创造力
- Good news | congratulations on the addition of 5 new committers in Apache linkage (incubating) community
- Qixia fire department carries out fire safety training on construction site
- You cannot call Glide. get() in registerComponents(), use the provided Glide instance instead
- Wealth freedom skills: commercialize yourself
猜你喜欢

【哈希表】很简单的拉链法哈希结构,以至于效果太差,冲突太多,链表太长

多媒体元素,音频、视频

MySQL开发环境

XGBoost, lightGBM, CatBoost——尝试站在巨人的肩膀上

Classic model - Nin & googlenet

进度条

Classic model – RESNET

Stm32cubemx: watchdog ------ independent watchdog and window watchdog

Xgboost, lightgbm, catboost -- try to stand on the shoulders of giants

【哈希表】改进,拉链法哈希结构——直接用两个索引查找,不用每次都hash和%一遍
随机推荐
redux-thunk 简单案例,优缺点和思考
Classic model – RESNET
国信金太阳靠谱吗?开证券账户安全吗?
Deletelater Usage Summary in QT
项目部署遇到的问题-生产环境
经典模型——AlexNet
校园创客空间的硬件造物原理
【论文笔记】Learning to Grasp with Primitive Shaped Object Policies
USB peripheral driver - Enumeration
MySQL开发环境
Problems encountered in project deployment - production environment
解决uniapp插件robin-editor设置字体颜色和背景颜色报错的问题
usb peripheral 驱动 - 枚举
mysql存储过程
Double carbon bonus + great year of infrastructure construction 𞓜 deep ploughing into the field of green intelligent equipment for water conservancy and hydropower
P2483-[template]k short circuit /[sdoi2010] Magic pig college [chairman tree, pile]
Todolist incomplete, completed
2022年挖财证券开户安全嘛?
Scratch returns 400
Is it safe to open an account in flush online? How to open a brokerage account online