CN113114655A - Binary data interaction protocol design method based on TCP/IP - Google Patents

Binary data interaction protocol design method based on TCP/IP Download PDF

Info

Publication number
CN113114655A
CN113114655A CN202110372790.6A CN202110372790A CN113114655A CN 113114655 A CN113114655 A CN 113114655A CN 202110372790 A CN202110372790 A CN 202110372790A CN 113114655 A CN113114655 A CN 113114655A
Authority
CN
China
Prior art keywords
box
data
version
tcp
design method
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110372790.6A
Other languages
Chinese (zh)
Inventor
汪云
刘毅
林涛睿
汤园生
陈阳
邱真
柴涛涛
王涛
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Vclusters Information Technology Co ltd
Original Assignee
Shenzhen Vclusters Information Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Vclusters Information Technology Co ltd filed Critical Shenzhen Vclusters Information Technology Co ltd
Priority to CN202110372790.6A priority Critical patent/CN113114655A/en
Publication of CN113114655A publication Critical patent/CN113114655A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/06Notations for structuring of protocol data, e.g. abstract syntax notation one [ASN.1]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The invention discloses a design method of a binary data interaction protocol based on TCP/IP, which supports the interaction of text and binary content and is convenient for protocol upgrading and expansion. The problems that when a protocol based on text data transmits binary format data such as pictures and videos, the protocol data packet is expanded and is not suitable for certain environments with harsh network requirements due to the fact that Base64 encoding is carried out to convert the protocol data into a text format are effectively solved.

Description

Binary data interaction protocol design method based on TCP/IP
Technical Field
The invention relates to the technical field of data interaction, in particular to a design method of a binary data interaction protocol based on TCP/IP.
Background
Under the background of the internet big data era, data transmitted by a network is complex, the format of transmitted data is changed continuously with the continuous change of user requirements and the continuous upgrade of a system, which requires that the system needs to support continuous expansion when an interactive interface is designed, and data in various formats needs to be supported for transmission, although protocol expansion based on a text format is very convenient, when a protocol based on the text data transmits binary format data such as pictures, videos and the like, Base64 coding is generally required to be converted into the text format, so that protocol data packets are expanded and expanded, and the method is not suitable for certain environments with harsh network requirements.
Therefore, further improvements are needed in the art.
Disclosure of Invention
Aiming at the problems in the prior art, the invention provides a binary data interaction protocol design method based on TCP/IP.
In order to achieve the purpose, the invention adopts the following specific scheme:
a binary data interaction protocol design method based on TCP/IP is provided, which comprises the following steps: s1, defining a data packet, wherein the whole data packet transmitted each time is defined as a Box;
s2, describing a data packet, and describing a Box by using pseudo codes;
s3, packaging data;
s4, data transmission;
s5, receiving data;
and S6, data analysis.
Further, S1 further includes:
s11, defining Box as a Data block containing Size, Type and Data, wherein the Data part can contain Fields and other boxes, and the Size and Type parts are called Header of Box;
and S12, storing the data in the Box by using a big-endian format.
Further, S2 further includes: all Box data are defined to be aligned according to 8 bits in the memory.
Further, S2 further includes: fields of version and flags are added to the Box, wherein the version describes the version of the Box with 8 bits, and the flag uses 24 bits as a series of bit flags for extension.
Further, S3 further includes:
s31, before data packaging, preparing a memory Buffer area Buffer, wherein the size of the Buffer area can accommodate the whole Box data;
s32, using a pointer or index pPreeData to point to the free position of the Buffer area, starting from the head of Buffer, after writing data in the Buffer, moving the pPreeData backwards to ensure that the pPreeData is at the tail of Box;
s33, recording the position of the Size field of Box in the buffer area by using the pointer or index pBoxsize;
s34, writing Box Type and updating pPreeData;
s35, writing the fields specified by Version and flag according to the Box protocol description and updating pPreeData;
and S36, after all data are written, calculating the size of Box according to the position of pFieData, and writing the Box into the pBoxSize.
Further, S35 further includes: and judging whether the fields specified by Version and flag exist.
Further, S5 further includes:
s51, when receiving the data packet, the client or the server firstly receives the Box size of 4 bytes, and then analyzes the content of the 4 bytes according to the big end byte order to obtain the Box size N;
s52, receiving N-4 bytes of data, thus completing the data reception of a whole Box;
and S53, storing the data of one Box in a continuous memory.
Further, S6 further includes:
s61, analyzing Box Size and Box Type;
and S62, finding the Box description of the corresponding type according to the protocol description document, and parsing the Box content byte by byte until the whole Box is parsed.
Further, S62 further includes: judging whether the Box contains Version and Flag fields, when the Box contains Version and Flag fields, analyzing the data of the corresponding Version according to the Version information of the current Box, and if the Version is unknown, skipping the data analysis of the whole Box.
By adopting the technical scheme of the invention, the invention has the following beneficial effects:
the invention discloses a data interaction method in binary format, which supports the interaction of text and binary content and is convenient for protocol upgrading and expansion; the problems that when a protocol based on text data transmits binary format data such as pictures and videos, Base64 encoding conversion is generally carried out to convert the binary format data into a text format, so that the expansion of protocol data packets is increased, and the protocol data packets are not suitable for certain environments with harsh network requirements are effectively solved.
Drawings
FIG. 1 is a flow diagram of a binary data interaction protocol design in accordance with an embodiment of the present invention;
FIG. 2 is a Box structure diagram according to an embodiment of the present invention;
FIG. 3 is an illustration of the fields in Box according to an embodiment of the present invention;
FIG. 4 is a diagram of a tst1 Box memory architecture in accordance with an embodiment of the present invention;
FIG. 5 is a diagram of a tst2 Box memory architecture according to an embodiment of the present invention;
FIG. 6 is a timing diagram of data interaction in accordance with an embodiment of the present invention.
Detailed Description
The invention is further described below with reference to the following figures and specific examples.
With reference to fig. 1-5: summary of the method principles/procedures of the present invention
1.0 this method provides that the entire packet transmitted at a time is called a Box.
2.1 packet definition
Box is defined as: a Data block containing Size (Size), Type (Type), Data (Data), wherein the Data portion may contain Fields (Fields), other Box. The Size and type parts are called the Box's Header. The method provides that data in the Box is stored by using a big-end endian format.
The structure of Box is shown in fig. 2.
The description of each field is shown in FIG. 3:
2.2 packet description
For ease of viewing and understanding, when describing a Box, pseudo code is used for description. As follows:
aligned(8)class Box(unsigned int(32)boxtype){
unsigned int(32)size;
unsigned int(32)type=boxtype;
}
wherein, aligned (8) indicates that the memory is aligned according to 8 bits, namely 1 Byte. unsigned int (32) represents a 32-bit unsigned integer.
The method provides that all Box data are aligned in the memory according to 8bit, namely 1 Byte.
The version and flag fields are commonly used in many boxes, and such a Box with version and flag fields is called a FullBox and can be described as follows using a pseudo code:
aligned(8)class FullBox(unsigned int(32)boxtype,unsigned int(8)v,bit(24)f)extends Box(boxtype){
unsigned int(8)version=v;
bit(24)flags=f;
}
extensions means that the FullBox inherits the Box defined above, and in addition to the fields of the Box, there are version and flags fields, where version (8bit) describes the version of the Box, and flag (24bit) is a series of bit flags, typically used for extensions. Usually, when a Box is parsed, the version number needs to be matched, the content of the current Box needs to be parsed according to the protocol description of the corresponding version, and if the version number is unknown, the parsing of the whole Box is skipped. This is the basis for convenient extension of the protocol.
Box and FullBox defined here are the basis of all other types of boxes, and when describing other boxes, if the Box needs to use the version number, then the Box is inherited, otherwise, the Box is inherited. For example, Box with 2 32-bit unsigned integer numbers of type 'tst 1' and version number 0 can be described as:
aligned(8)class TestBox1(unsigned int(32)boxtype,unsigned int(8)v,bit(24)f)extends FullBox(boxtype,v,f){
unsigned int(32)filed1;
unsigned int(32)filed2;
}
the memory structure of the 'tst 1' Box is shown in fig. 4.
Defining a Box of type 'tst 2', version number 0 containing 2 unsigned integer numbers of 32 bits and a Box of 'tst 1' can be described as:
aligned(8)class TestBox2(unsigned int(32)boxtype,unsigned int(8)v,bit(24)f)extends FullBox(boxtype,v,f){
unsigned int(32)filed1;
unsigned int(32)filed2;
TestBox1 box1;
}
the memory structure of the 'tst 2' Box is shown in fig. 5.
In the actual application process, the definition and description of other types of boxes are extended to the actual application by referring to the two examples, and the Box description is written into the interface description document so as to perform data interaction with a third party. The method does not specify the concrete content of Data of Box, and the Data is required to be defined in actual use, so that the Data part can also be defined as a character string with the length of BoxSize-8, and the method can also be used for interaction of text Data. The method does not specify the version of the Box, the general version number starts from 0, if the protocol version is upgraded in the actual use process, the version number is sequentially increased, and the content analysis is carried out according to the Box description of the corresponding version number when the data packet is analyzed.
2.3 data packing, sending, receiving and parsing
Whether the application layer is implemented by using TCP/IP or Websocket, the sequence diagram of data interaction between the client and the server is shown in FIG. 6.
2.3.1 data packing and Transmission
Before sending a data packet, a client or a server needs to complete the pre-packing of the data corresponding to the Box according to a protocol description document, write the data into a sending buffer area, and then send the data to an opposite end.
The following are Box data packing methods and steps:
(1) and before data packaging, preparing a memory Buffer area in advance, wherein the size of the Buffer area needs to be ensured to accommodate the whole Box data.
(2) And a pointer/index pFareData points to the idle position of the Buffer (from the head of the Buffer), and after data is written into the Buffer, the pFareData needs to move backwards to ensure that the pFareData is at the tail of the Box.
(3) Record the location of Box field in the Buffer using the pointer/index pBoxSize (pBoxSize is typically the Buffer header);
(4) writing a Box Type and updating pPreeData;
(5) write Version & flag (if any) and update pFreeData in specified fields according to Box's protocol description.
(6) After all data are written, calculating the size of Box according to the position of pFireData, and writing the Box into the position of pBoxSize.
Through the steps, the Box data which does not contain other child boxes can be packaged (note: the data needs to be stored according to big-end byte order).
And when the Box contains other child boxes, completing data packaging of the child boxes according to the methods (1) to (6), writing the data of the child boxes into the pFireData position, updating the pFireData value, and updating the Box Size until all the data are written into the Buffer.
2.3.2 data reception and parsing
When a client or a server receives a data packet, the size of a Box of 4 bytes is received, the content of the 4 bytes is analyzed according to the byte order of a big end to obtain the size N of the Box, and then the data of N-4 bytes is received, so that the data of the whole Box is received. To facilitate data parsing, the data of one Box is stored in a continuous memory.
After the whole Box data packet is received, analyzing the Box data according to the following method:
(1) analyzing Box Size and Box Type;
(2) finding out the Box description of the corresponding type according to the protocol description document, and analyzing the Box content byte by byte until the whole Box is analyzed. If the Box contains Version and Flag fields, the data of the corresponding Version needs to be analyzed according to the Version information of the current Box, and if the Version is unknown, the data analysis of the whole Box is skipped.
Generally, when an actual program is implemented, the parsing of each Box is written into a separate method/function, and when the Box includes other child boxes, the child boxes can be parsed only by inputting the data memory addresses of the child boxes and parsing the functions of the child boxes.
The method mainly describes an organization and analysis method of interactive data, and because a TCP/IP protocol stack can ensure the effectiveness of data transmission, the method uses an original TCP/IP or WebSocket protocol to transmit data for the convenience of data transmission and processing. When TCP link or WebSocket handshake is successfully established between the client and the server, the description data packet format of the method can be used for interaction. The method only describes the interactive data format and does not relate to the specific application on the protocol, so that the data security, the authority authentication and the like can be realized in an extended manner on the application layer based on the data packet format described by the method.
The above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention, and all modifications and equivalents of the present invention, which are made by the contents of the present specification and the accompanying drawings, or directly/indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (9)

1. A binary data interaction protocol design method based on TCP/IP is characterized by comprising the following steps:
s1, defining a data packet, wherein the whole data packet transmitted each time is defined as a Box;
s2, describing a data packet, and describing a Box by using pseudo codes;
s3, packaging data;
s4, data transmission;
s5, receiving data;
and S6, data analysis.
2. The TCP/IP-based binary data interaction protocol design method of claim 1, wherein S1 further comprises:
s11, defining Box as a Data block containing Size, Type and Data, wherein the Data part can contain Fields and other boxes, and the Size and Type parts are called Header of Box;
and S12, storing the data in the Box by using a big-endian format.
3. The TCP/IP-based binary data interaction protocol design method of claim 1, wherein S2 further comprises: all Box data are defined to be aligned according to 8 bits in the memory.
4. The TCP/IP-based binary data interaction protocol design method of claim 3, wherein S2 further comprises: fields of version and flags are added to the Box, wherein the version describes the version of the Box with 8 bits, and the flag uses 24 bits as a series of bit flags for extension.
5. The TCP/IP-based binary data interaction protocol design method of claim 1, wherein S3 further comprises:
s31, before data packaging, preparing a memory Buffer area Buffer, wherein the size of the Buffer area can accommodate the whole Box data;
s32, using a pointer or index pPreeData to point to the free position of the Buffer area, starting from the head of Buffer, after writing data in the Buffer, moving the pPreeData backwards to ensure that the pPreeData is at the tail of Box;
s33, recording the position of the Size field of Box in the buffer area by using the pointer or index pBoxsize;
s34, writing Box Type and updating pPreeData;
s35, writing the fields specified by Version and flag according to the Box protocol description and updating pPreeData;
and S36, after all data are written, calculating the size of Box according to the position of pFieData, and writing the Box into the pBoxSize.
6. The TCP/IP-based binary data interaction protocol design method of claim 5, wherein S35 further comprises: and judging whether the fields specified by Version and flag exist.
7. The TCP/IP-based binary data interaction protocol design method of claim 1, wherein S5 further comprises:
s51, when receiving the data packet, the client or the server firstly receives the Box size of 4 bytes, and then analyzes the content of the 4 bytes according to the big end byte order to obtain the Box size N;
s52, receiving N-4 bytes of data, thus completing the data reception of a whole Box;
and S53, storing the data of one Box in a continuous memory.
8. The TCP/IP-based binary data interaction protocol design method of claim 1, wherein S6 further comprises:
s61, analyzing Box Size and Box Type;
and S62, finding the Box description of the corresponding type according to the protocol description document, and parsing the Box content byte by byte until the whole Box is parsed.
9. The TCP/IP-based binary data interaction protocol design method of claim 8, wherein S62 further comprises: judging whether the Box contains Version and Flag fields, when the Box contains Version and Flag fields, analyzing the data of the corresponding Version according to the Version information of the current Box, and if the Version is unknown, skipping the data analysis of the whole Box.
CN202110372790.6A 2021-04-07 2021-04-07 Binary data interaction protocol design method based on TCP/IP Pending CN113114655A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110372790.6A CN113114655A (en) 2021-04-07 2021-04-07 Binary data interaction protocol design method based on TCP/IP

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110372790.6A CN113114655A (en) 2021-04-07 2021-04-07 Binary data interaction protocol design method based on TCP/IP

Publications (1)

Publication Number Publication Date
CN113114655A true CN113114655A (en) 2021-07-13

Family

ID=76714337

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110372790.6A Pending CN113114655A (en) 2021-04-07 2021-04-07 Binary data interaction protocol design method based on TCP/IP

Country Status (1)

Country Link
CN (1) CN113114655A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115334169A (en) * 2022-04-28 2022-11-11 深圳证券通信有限公司 Communication protocol coding method for saving network bandwidth

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1540523A (en) * 2003-10-30 2004-10-27 中兴通讯股份有限公司 Quick method for reading/writing buffer in single task
CN101802823A (en) * 2007-08-20 2010-08-11 诺基亚公司 Segmented metadata and indexes for streamed multimedia data
CN103843351A (en) * 2011-09-29 2014-06-04 三星电子株式会社 Method and apparatus for transmitting and receiving content
CN107787586A (en) * 2015-06-23 2018-03-09 三星电子株式会社 Method and apparatus for being sent and received signal in multimedia system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1540523A (en) * 2003-10-30 2004-10-27 中兴通讯股份有限公司 Quick method for reading/writing buffer in single task
CN101802823A (en) * 2007-08-20 2010-08-11 诺基亚公司 Segmented metadata and indexes for streamed multimedia data
CN103843351A (en) * 2011-09-29 2014-06-04 三星电子株式会社 Method and apparatus for transmitting and receiving content
CN107787586A (en) * 2015-06-23 2018-03-09 三星电子株式会社 Method and apparatus for being sent and received signal in multimedia system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115334169A (en) * 2022-04-28 2022-11-11 深圳证券通信有限公司 Communication protocol coding method for saving network bandwidth
CN115334169B (en) * 2022-04-28 2023-06-06 深圳证券通信有限公司 Communication protocol coding method capable of saving network bandwidth

Similar Documents

Publication Publication Date Title
US10237371B2 (en) Content management and transformation system for digital content
KR101027299B1 (en) System and method for history driven optimization of web services communication
EP2145452B1 (en) Method and system for extending the capabilities of embedded devices through network clients
US6714984B2 (en) Method and apparatus for media data transmission
CN100534071C (en) System and method for using packed compressed buffers for improved client server communication
KR101120796B1 (en) Session description message extensions
US20170099332A1 (en) Systems and methods using binary dynamic rest messages
US20030204555A1 (en) Method and apparatus for media data transmission
US20020087596A1 (en) Compact tree representation of markup languages
US20120203867A1 (en) Method and apparatus for receiving presentation metadata
KR19990066882A (en) Method and apparatus for compressing documents using markup language that can preserve syntax structure
CN102916991B (en) Method, system and device for transmitting data
JP2000047964A (en) Data transfer method on network, its device, its system, and recording medium having recorded data transfer program on network thereon
US20080313291A1 (en) Method and apparatus for encoding data
CN113225320A (en) Network message analysis method for keeping user configurable message format secret
CN113114655A (en) Binary data interaction protocol design method based on TCP/IP
US6571292B1 (en) Integration of structured document content with legacy 3270 applications
US20070239818A1 (en) Method, apparatus and system for transforming, converting and processing messages between multiple systems
Bressoud et al. The HyperText Transfer Protocol
CN106487855B (en) File uploading method, file accessing method, file uploading device, file accessing device and equipment
US20070226263A1 (en) Method, apparatus and system for transforming, converting and processing messages between multiple systems
US20040015780A1 (en) Position-independent access to data elements in an electronic document
Rix et al. Transformation between XML and CBOR for network load reduction
CN113452759B (en) Method and device for sending and receiving websocket communication message
WO2007006090A1 (en) Systems and methods for use in transforming electronic information into a format

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20210713

RJ01 Rejection of invention patent application after publication