CN113452759A - Method and device for sending and receiving websocket communication message - Google Patents

Method and device for sending and receiving websocket communication message Download PDF

Info

Publication number
CN113452759A
CN113452759A CN202110633250.9A CN202110633250A CN113452759A CN 113452759 A CN113452759 A CN 113452759A CN 202110633250 A CN202110633250 A CN 202110633250A CN 113452759 A CN113452759 A CN 113452759A
Authority
CN
China
Prior art keywords
message
target
protocol number
byte
encrypted
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.)
Granted
Application number
CN202110633250.9A
Other languages
Chinese (zh)
Other versions
CN113452759B (en
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.)
Wuhan Dobit Information Technology Co ltd
Original Assignee
Wuhan Dobit 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 Wuhan Dobit Information Technology Co ltd filed Critical Wuhan Dobit Information Technology Co ltd
Priority to CN202110633250.9A priority Critical patent/CN113452759B/en
Publication of CN113452759A publication Critical patent/CN113452759A/en
Application granted granted Critical
Publication of CN113452759B publication Critical patent/CN113452759B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/04Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks
    • H04L63/0428Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks wherein the data content is protected, e.g. by encrypting or encapsulating the payload
    • 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/03Protocol definition or specification 
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/50Reducing energy consumption in communication networks in wire-line communication networks, e.g. low power modes or reduced link rate

Abstract

The application relates to a method and a device for sending and receiving a websocket communication message, wherein the sending method comprises the steps of defining a protocol number and a structural body of a target message; writing a target message in the structure body to obtain a message body; based on ArrayBuffer storage, the protocol number and the message body are packaged and encrypted to obtain an encrypted message, and the encrypted message is sent to the receiving terminal network equipment through websocket communication. The method defines the protocol numbers and the structural bodies of different messages, and performs ArrayBuffer binary writing and data fusion encryption on different types of data, so that unified specification is performed on message structure sending and receiving, data encryption is performed, and management and use of developers are facilitated.

Description

Method and device for sending and receiving websocket communication message
Technical Field
The present application relates to the field of data communication, and in particular, to a method and an apparatus for sending and receiving a websocket communication packet.
Background
The websocket communication transmission data types mainly comprise a blob and an ArrayBuffer, wherein the blob type is a binary object which is specially used for supporting file operation at the front end; the ArrayBuffer type is a general binary buffer area at the front end, is similar to an array, but has a plurality of differences in API and characteristics; when non-large file communication transmission is carried out, an ArrayBuffer is generally adopted, various data structures required during communication are assembled into messages, the messages are registered in a binary buffer, and websocket message sending and receiving are carried out.
At present, different developers have different usage habits, and define various types of refuted message structures, but still all data types are not covered, so that the message transmission type is limited, and the security is reduced.
Disclosure of Invention
In order to overcome the defects of the prior art, the application provides a method and a device for sending and receiving a websocket communication message, wherein the method uses an ArrayBuffer type to carry out websocket communication, carries out unified specification on message structure sending and receiving, carries out data encryption, and is convenient for management and developers to use.
In a first aspect, a method for sending a websocket communication packet includes:
defining a protocol number and a structure body of a target message;
writing a target message in the structure body to obtain a message body;
and based on ArrayBuffer storage, packaging and encrypting the protocol number and the message body to obtain an encrypted message, and sending the encrypted message to receiving-end network equipment through websocket communication.
Optionally, the target packet includes a common message and a target message, and the defining of the protocol number and the structure of the target packet includes:
the protocol number of the target message is provided with a sending structural body and a receiving structural body;
setting a message variable name of the sending structure body according to the requirement of a target message, wherein the attribute of the message variable name comprises a variable type and a byte number multiple required by an ultra-long variable;
writing a target message in the structure body to obtain a message body, including:
and mapping the attributes of the target message with the variable types defined in the structure body in a one-to-one correspondence mode.
Optionally, the encapsulating and encrypting the protocol number and the message body based on the ArrayBuffer storage to obtain an encrypted message includes:
respectively determining a protocol number and the byte length required by the target message, and respectively storing array buffers according to the byte length required by the protocol number and the byte length required by the target message;
and encrypting the stored protocol number and the Buffer data of the target message, and taking the encrypted Buffer data as an encrypted message.
Optionally, the determining the protocol number and the byte length required by the target message respectively, performing ArrayBuffer storage respectively according to the byte length required by the protocol number and the byte length required by the target message, encrypting the Buffer data of the stored protocol number and the stored target message, and using the encrypted Buffer data as an encrypted message includes:
storing the protocol number by adopting a preset fixed length byte, wherein the fixed length byte comprises a storage bit of a preset version number and a storage bit of the protocol number;
writing the version number into a preset ArrayBuffer1 first memory by using a preset view writing method, converting the protocol number into a decimal number, writing the decimal number into the ArrayBuffer1 first memory, and setting byte offset and byte order;
analyzing the target byte length required to be stored by the target message;
creating an ArrayBuffer2 second memory corresponding to the target byte length, traversing message values in the target message according to a preset view writing method, and writing the message values into the ArrayBuffer2 second memory;
acquiring the sum of the byte lengths of the ArrayBuffer1 first memory and the ArrayBuffer2 second memory, and creating an ArrayBuffe3 third memory;
reading the protocol number and the Buffer data of the target message, writing the protocol number and the Buffer data into a third memory of the array Buffer 3, encrypting the written Buffer data, and taking the encrypted Buffer data as an encrypted message.
Optionally, parsing the target byte length required to be stored by the target message includes:
traversing the message variable name of the target message, if the data type of the message variable name is in a preset enumerated data type list, starting to calculate the byte length corresponding to the data type of the message variable name, respectively setting a byte total length variable and a basic data maximum byte length variable, and cumulatively calculating to obtain the byte length required by the storage content of the target message and the maximum byte number required by a single message value.
Optionally, the preset view writing method corresponds to a preset view reading method, and is set by view DataView, and the version number, the protocol number, and the data types of different message variable names all preset corresponding view writing methods and view reading methods, where the view writing method of the version number is setUint8, the view reading method of the version number is getUint8, the view writing method of the protocol number is setUint16, and the view reading method of the protocol number is getUint 16.
In a second aspect, the present application provides a method for receiving a websocket communication packet, where the method includes:
acquiring an encrypted message, and acquiring a protocol number of the encrypted message according to a preset view reading method;
creating a view and acquiring a message body of the encrypted message;
indexing and acquiring the structural body of the message body according to the protocol number;
and traversing the message variable names of the received structure in the structure, reading all message values of the structure, and integrating all the message values into analysis data of the encrypted message.
Optionally, traversing the message variable name of the received structure in the structure, reading all message values of the structure, and integrating all the message values into the analysis data of the encrypted message, including:
traversing the message variable names of the receiving structure in the structure, respectively setting byte total length variables and basic data maximum byte length variables, and performing cumulative calculation to obtain target byte lengths stored by the message body, wherein the target byte lengths comprise the byte total lengths of message contents and the longest byte number required by a single message value;
and sequentially reading message values corresponding to the message variable names of the structure body according to the target byte length and a preset view reading method, and integrating all the message values into analysis data of the encrypted message.
In a third aspect, the present application provides a device for sending a websocket communication packet, where the device includes:
the definition module is used for defining the protocol number and the structural body of the target message;
the writing module is used for writing the target message in the structure body to obtain a message body;
and the encapsulation module is used for encapsulating and encrypting the protocol number and the message body based on ArrayBuffer storage to obtain an encrypted message, and sending the encrypted message to the receiving end network equipment through websocket communication.
In a fourth aspect, the application provides a receiving apparatus for a websocket communication packet, where the sending apparatus includes:
the acquisition module is used for acquiring an encrypted message and acquiring a protocol number of the encrypted message according to a preset view reading method;
the analysis module is used for creating a view and acquiring a message body of the encrypted message;
the index module is used for indexing and acquiring the structural body of the message body according to the protocol number;
and the reading module is used for traversing the message variable names of the received structural bodies in the structural bodies, reading all message values of the structural bodies and integrating all the message values into analysis data of the encrypted messages.
This application includes beneficial technological effect: by defining the protocol numbers and the structural bodies of different messages, ArrayBuffer binary writing and data fusion encryption are carried out on different types of data, so that unified specification is carried out on the sending and receiving of message structures, data encryption is carried out, and management and use of developers are facilitated.
Drawings
Fig. 1 is a flowchart of a method according to an embodiment of a method for sending a websocket communication packet provided by the present invention;
fig. 2 is a flowchart of a method according to an embodiment of a method for receiving a websocket communication packet provided by the present invention;
fig. 3 is a schematic block diagram of an embodiment of a device for sending a websocket communication packet provided by the present invention;
fig. 4 is a schematic block diagram of an embodiment of a device for receiving a websocket communication packet provided in the present invention.
Detailed Description
The present application is described in further detail below with reference to figures 1-4.
The embodiment of the application discloses a method for sending a websocket communication message, and with reference to fig. 1, the method includes:
and S11, defining the protocol number and the structure body of the target message.
In this embodiment, the weesocket communication can be performed by using an ArrayBuffer type, which is developed by using a JavaScript language. When the websocket communication is used for sending and receiving messages, messages are distinguished through protocol numbers in the messages, such as 0xa001, common messages include public messages and target messages, each target message sets corresponding structural body information according to requirements, and in a specific application example, the method includes the following steps:
// common code, structure of transmission,
Figure BDA0003104448670000061
Figure BDA0003104448670000071
in consideration of the multiplexing problem of protocol numbers, each protocol number is provided with a transmitting structure and a receiving structure, that is, each protocol number has req and resp; in one embodiment, the protocol number is 16-ary data, the protocol number corresponds to a structure, and the structure is in an object enumeration form.
Further, the message variable name of the sending structure body is set according to the requirement of the target message,
the attributes of the message variable name include the variable type and the byte number multiple required by the extra-long variable. It should be noted that, in the attributes in the structure, the variable name required by each target message is enumerated, and the type attribute is used to indicate the type of the current variable; in addition, for some extra-long message variable names, a length attribute is newly added to indicate the number of byte multiples required by the current extra-long message variable.
And S12, writing the target message into the structure body to obtain a message body.
In this embodiment, a target message to be transmitted is written according to a defined structure, and in a specific application example, the following is performed:
Figure BDA0003104448670000072
Figure BDA0003104448670000081
in one embodiment, the protocol number is associated with the structure, the protocol number cannot be reused, the attributes of the target message are mapped in a one-to-one correspondence with variable types defined in the structure, the data types cannot be changed during writing, and the data types cannot be lost or added.
S13, based on ArrayBuffer storage, the protocol number and the message body are packaged and encrypted to obtain an encrypted message, and the encrypted message is sent to the receiving terminal network equipment through websocket communication.
Specifically, the byte lengths required by the protocol number and the target message are respectively determined, and ArrayBuffer storage is respectively carried out according to the byte length required by the protocol number and the byte length required by the target message; further, the stored protocol number and the Buffer data of the target message are encrypted, and the encrypted Buffer data is used as an encrypted message.
The following describes the process of encapsulating and encrypting the protocol number and the message body.
S131, assembling a protocol number.
In one embodiment, the protocol number is stored by adopting a preset fixed length byte, wherein the fixed length byte comprises a storage bit with a preset version number and a storage bit with the protocol number; in a specific application example, the default is to use 4 bytes to transmit the protocol number, the first two bits transmit version number information, and the last two bits are used to transmit hexadecimal data of the protocol number, which is specifically done as follows:
var b=new ArrayBuffer(4),
c=new DataView(b);
c.setuint8(0,this.bigVer);
c.setUint8(1,this.littleVer);
// obtaining hexadecimal protocol numbers, conversion to decimal, e.g. a008- >40968
1=parseInt(1.substr(2),16);
c.setuint16(2,l,this._LITTLE_ENDIAN);
Further, the version number is written into a preset ArrayBuffer1 first memory by using a setUint8 method through a view DataView; because the protocol number is represented by hexadecimal, two bytes need to be allocated for storage, after the protocol number is converted into decimal, the protocol number is written into the first memory of the array buffer1 by using a setup 16 method, and a byte offset and a byte order are set, in an embodiment, the byte offset is set to be 2, and a little-end byte order littleEndian is used.
S132, assembling the message body.
1. The target byte length that needs to be stored for the target message is parsed.
It should be noted that the target message and the protocol number have different fixed length byte storage, and the target message needs to analyze the byte length required by the target message due to the difference of the content data and the different byte length used at last; it is worth mentioning that before parsing the byte length required by the target message, all commonly used data types need to be enumerated to generate an enumerated data type list, and an initial byte length is set, so that interpretation failure caused by manual error is avoided, for example: CHAR:1, INT8:1, UINT8:1, INT16:1, UINT16:1, INT32:1, UINT32:1, UINT64:1, INT64:1, BOOL:1, and the like.
Specifically, traversing the message variable name of the target message, if the data type of the message variable name is in a preset enumerated data type list, starting to calculate the byte length corresponding to the data type of the message variable name, respectively setting a byte total length variable length and a basic data maximum byte length variable maxBaseDataLen, and cumulatively calculating the byte length required by the storage content of the target message and the maximum byte number required by a single message value. In one embodiment, a for loop may be employed to traverse the message variable name of the target message.
It should be noted that, when parsing a message type, which is a message variable name, short byte data types, such as Number, book, Char, and the like, are accumulated by using a default byte length, that is, length + default. For long byte data types such as INT16_ ARRAY, FLOAT _ ARRAY, etc., the required byte length is a default length multiplied by the number of bytes required by the current variable setting, i.e., length + default.
And if the message variable is named as STRUCT in traversal, the current data type is represented as a packaged public message structure, the message of the public structure is taken out, the specific message type is analyzed, and the length is continuously accumulated.
For a basic data maximum BYTE length variable maxBaseDataLen, BYTE alignment of BYTE _ ALIGNED is set, the limit is 4 BYTEs, when length accumulation is carried out in codes, if the length required by the current data type is smaller than BYTE _ ALIGNED, the output value of the maxBaseDataLen finally takes the maximum value, and otherwise, the maximum value is the limit value of the BYTE _ ALIGNED.
2. And creating an ArrayBuffer2 second memory corresponding to the target byte length, traversing the message value in the target message according to a preset view writing method, and writing the message value into an ArrayBuffer2 second memory.
It should be noted that, according to the target byte length that the target message needs to store, a memory array buffer2 that corresponds to the byte length is created as a new array buffer (length); traversing the target message again, acquiring the message value of the message variable name of the corresponding structure from the target message, and writing the message value into the memory through a new view DataView (ArrayBuffer2), in a specific application embodiment, part of the following method is as follows 1:
table 1 write protocol rules for partial data types
Figure BDA0003104448670000111
It should be noted that a preset view writing method corresponds to a preset view reading method, and is set by view DataView, and the version number, the protocol number, and the data types of different message variable names all preset corresponding view writing methods and view reading methods, where the view writing method of the version number is setUint8, the view reading method of the version number is getUint8, the view writing method of the protocol number is setUint16, the view reading method of the protocol number is getUint16, and the view writing methods of the data types of different message variable names are visible in table 1.
S133, fusion encryption of protocol number and message body
In one embodiment, the sum of the byte lengths of the ArrayBuffer1 and the second memory ArrayBuffer2 is obtained according to the byte length of the first memory and the byte length of the second memory, and an ArrayBuffer 3 third memory is created.
Further, reading the protocol number and the Buffer data of the target message by adopting a getUnit8 view, writing the protocol number and the Buffer data into an ArrayBuffe3 third memory by adopting a setUnit8 view, encrypting the written Buffer data, and transmitting the encrypted Buffer data as an encrypted message through websocket.
Referring to fig. 2, this embodiment also provides a method for receiving a websocket communication packet, where the method includes:
s21: and acquiring an encrypted message, and acquiring a protocol number of the encrypted message according to a preset view reading method.
S22: and creating a view and acquiring a message body of the encrypted message.
S23: and according to the protocol number, indexing to obtain a structural body of the message body.
S24: and traversing the message variable names of the structure, reading all message values of the structure, and integrating all message values into analysis data of the encrypted message.
It should be noted that the message of the encrypted message is ArrayBuffer data, the message is reversely processed according to the encryption rule to be decrypted to obtain GetBuffer, and a new view new DataView (GetBuffer) is newly created and read.
In one embodiment, a message header is obtained first, and according to a preset protocol rule, version number information of the first two bytes stored in the message is obtained by using a getUint8 view; the protocol number data CmdType is obtained using the getUint16 view. Further, a new DataView view is created, and data of the message except the first 4 bytes, namely the message content MsgData, is obtained; the message content is restored in a reverse process of writing, according to the protocol number, the structure corresponding to the current encrypted message can be indexed, and the message definition is read in the resp object, namely the receiving structure, in a specific application example, the method is as follows:
Figure BDA0003104448670000121
Figure BDA0003104448670000131
further, for the message definition structure, a byte total length variable and a basic data maximum byte length variable are respectively set, and a target byte length stored in the message body is obtained through cumulative calculation, wherein the target byte length comprises the byte total length of the message content and the longest byte number required by a single message value.
And sequentially reading message values corresponding to the message variable names of the structure body according to the target byte length and a preset view reading method, and integrating all the message values into analysis data of the encrypted message. It should be noted that the message reading method is the reverse process of the message writing method, and is not described herein in detail.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
The embodiment also provides a device for sending the websocket communication message, wherein the device for sending the websocket communication message corresponds to the method for sending the websocket communication message in the embodiment one to one. As shown in fig. 3, the device for sending a websocket communication packet includes a definition module 301, a B module, a write module 302, and an encapsulation module 303. The functional modules are explained in detail as follows:
a defining module 301, configured to define a protocol number and a structure of a target packet;
a writing module 302, configured to write a target message in a structure to obtain a message body;
and the encapsulating module 303 is configured to encapsulate and encrypt the protocol number and the message body based on the ArrayBuffer storage to obtain an encrypted message, and send the encrypted message to the receiving-end network device through websocket communication.
For specific limitations of each module of the device for sending the websocket communication packet, reference may be made to the above limitations on the sending method of the websocket communication packet, and details are not described herein again. All modules in the websocket communication message sending device can be completely or partially realized through software, hardware and a combination of the software and the hardware. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
The embodiment also provides a receiving device of the websocket communication message, which corresponds to the receiving method of the websocket communication message in the embodiment one to one. As shown in fig. 4, the receiving apparatus of the websocket communication packet includes an obtaining module 401, an analyzing module 402, an indexing module 403, and a reading module 404. The functional modules are explained in detail as follows:
an obtaining module 401, configured to obtain an encrypted message, and obtain a protocol number of the encrypted message according to a preset view reading method;
the parsing module 402 is configured to create a view and obtain a message body of the encrypted message;
an indexing module 403, configured to index and obtain a structure of the message body according to the protocol number;
the reading module 404 is configured to traverse the message variable name of the received structure in the structure, read all message values of the structure, and integrate all message values into the analysis data of the encrypted message.
The application defines the protocol numbers and the structural bodies of different messages, and performs ArrayBuffer binary writing and data fusion encryption on different types of data, so that unified specification is performed on message structure sending and receiving, data encryption is performed, and management and use of developers are facilitated.
For specific limitations of each module of the apparatus for receiving a websocket communication packet, reference may be made to the above limitations on the method for receiving a websocket communication packet, and details are not described herein again. All modules in the websocket communication message receiving device can be completely or partially realized through software, hardware and a combination of the software and the hardware. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules, so as to perform all or part of the functions described above. The above embodiments are preferred embodiments of the present application, and the protection scope of the present application is not limited by the above embodiments, so: all equivalent changes made according to the structure, shape and principle of the present application shall be covered by the protection scope of the present application.

Claims (10)

1. A method for sending a websocket communication message is characterized in that: the sending method comprises the following steps:
defining a protocol number and a structure body of a target message;
writing a target message in the structure body to obtain a message body;
and based on ArrayBuffer storage, packaging and encrypting the protocol number and the message body to obtain an encrypted message, and sending the encrypted message to receiving-end network equipment through websocket communication.
2. The method for sending websocket communication packets according to claim 1, wherein: the target message comprises a public message and a target message, and the definition of the protocol number and the structure body of the target message comprises the following steps:
the protocol number of the target message is provided with a sending structural body and a receiving structural body;
setting a message variable name of the sending structure body according to the requirement of a target message, wherein the attribute of the message variable name comprises a variable type and a byte number multiple required by an ultra-long variable;
writing a target message in the structure body to obtain a message body, including:
and mapping the attributes of the target message with the variable types defined in the structure body in a one-to-one correspondence mode.
3. The method for sending websocket communication packets according to claim 1, wherein: the encapsulating and encrypting the protocol number and the message body based on the ArrayBuffer storage to obtain an encrypted message includes:
respectively determining a protocol number and the byte length required by the target message, and respectively storing array buffers according to the byte length required by the protocol number and the byte length required by the target message;
and encrypting the stored protocol number and the Buffer data of the target message, and taking the encrypted Buffer data as an encrypted message.
4. The method for sending websocket communication packets according to claim 1, wherein: the determining the protocol number and the byte length required by the target message respectively, performing ArrayBuffer storage respectively according to the byte length required by the protocol number and the byte length required by the target message, encrypting the stored protocol number and the Buffer data of the target message, and using the encrypted Buffer data as an encrypted message includes:
storing the protocol number by adopting a preset fixed length byte, wherein the fixed length byte comprises a storage bit of a preset version number and a storage bit of the protocol number;
writing the version number into a preset ArrayBuffer1 first memory by using a preset view writing method, converting the protocol number into a decimal number, writing the decimal number into the ArrayBuffer1 first memory, and setting byte offset and byte order;
analyzing the target byte length required to be stored by the target message;
creating an ArrayBuffer2 second memory corresponding to the target byte length, traversing message values in the target message according to a preset view writing method, and writing the message values into the ArrayBuffer2 second memory;
acquiring the sum of the byte lengths of the ArrayBuffer1 first memory and the ArrayBuffer2 second memory, and creating an ArrayBuffe3 third memory;
reading the protocol number and the Buffer data of the target message, writing the protocol number and the Buffer data into a third memory of the array Buffer 3, encrypting the written Buffer data, and taking the encrypted Buffer data as an encrypted message.
5. The method for sending the websocket communication packet according to claim 4, wherein analyzing the target byte length required to be stored in the target message includes:
traversing the message variable name of the target message, if the data type of the message variable name is in a preset enumerated data type list, starting to calculate the byte length corresponding to the data type of the message variable name, respectively setting a byte total length variable and a basic data maximum byte length variable, and cumulatively calculating to obtain the byte length required by the storage content of the target message and the maximum byte number required by a single message value.
6. The method for receiving a websocket communication packet according to claim 5, wherein: the preset view writing method corresponds to a preset view reading method, and is set by view DataView, and the version number, the protocol number and the data types of different message variable names all preset corresponding view writing methods and view reading methods, wherein the view writing method of the version number is setUint8, the view reading method of the version number is getUint8, the view writing method of the protocol number is setUint16, and the view reading method of the protocol number is getUint 16.
7. A method for receiving a websocket communication message is characterized by comprising the following steps: the receiving method comprises the following steps:
acquiring an encrypted message, and acquiring a protocol number of the encrypted message according to a preset view reading method;
creating a view and acquiring a message body of the encrypted message;
indexing and acquiring the structural body of the message body according to the protocol number;
and traversing the message variable names of the received structure in the structure, reading all message values of the structure, and integrating all the message values into analysis data of the encrypted message.
8. The method for receiving a websocket communication packet according to claim 7, wherein: traversing the message variable name of the received structure in the structure, reading all message values of the structure, and integrating all the message values into analysis data of the encrypted message, wherein the method comprises the following steps:
traversing the message variable names of the receiving structure in the structure, respectively setting byte total length variables and basic data maximum byte length variables, and performing cumulative calculation to obtain target byte lengths stored by the message body, wherein the target byte lengths comprise the byte total lengths of message contents and the longest byte number required by a single message value;
and sequentially reading message values corresponding to the message variable names of the structure body according to the target byte length and a preset view reading method, and integrating all the message values into analysis data of the encrypted message.
9. A websocket communication message sending device is characterized in that: the transmission apparatus includes:
the definition module is used for defining the protocol number and the structural body of the target message;
the writing module is used for writing the target message in the structure body to obtain a message body;
and the encapsulation module is used for encapsulating and encrypting the protocol number and the message body based on ArrayBuffer storage to obtain an encrypted message, and sending the encrypted message to the receiving end network equipment through websocket communication.
10. A receiving device of websocket communication messages is characterized in that: the transmission apparatus includes:
the acquisition module is used for acquiring an encrypted message and acquiring a protocol number of the encrypted message according to a preset view reading method;
the analysis module is used for creating a view and acquiring a message body of the encrypted message;
the index module is used for indexing and acquiring the structural body of the message body according to the protocol number;
and the reading module is used for traversing the message variable names of the received structural bodies in the structural bodies, reading all message values of the structural bodies and integrating all the message values into analysis data of the encrypted messages.
CN202110633250.9A 2021-06-07 2021-06-07 Method and device for sending and receiving websocket communication message Active CN113452759B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110633250.9A CN113452759B (en) 2021-06-07 2021-06-07 Method and device for sending and receiving websocket communication message

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110633250.9A CN113452759B (en) 2021-06-07 2021-06-07 Method and device for sending and receiving websocket communication message

Publications (2)

Publication Number Publication Date
CN113452759A true CN113452759A (en) 2021-09-28
CN113452759B CN113452759B (en) 2023-03-24

Family

ID=77810933

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110633250.9A Active CN113452759B (en) 2021-06-07 2021-06-07 Method and device for sending and receiving websocket communication message

Country Status (1)

Country Link
CN (1) CN113452759B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106209812A (en) * 2016-07-04 2016-12-07 深圳市得润车联科技有限公司 A kind of method of internet-of-things terminal platform data encapsulation
US20170099332A1 (en) * 2014-03-21 2017-04-06 Ptc Inc. Systems and methods using binary dynamic rest messages
CN107835150A (en) * 2017-09-15 2018-03-23 广州唯品会研究院有限公司 A kind of full media customer service dispatching method and system
CN110875897A (en) * 2018-08-29 2020-03-10 阿里巴巴集团控股有限公司 Data transmission method, device, server and storage medium
CN112363849A (en) * 2020-10-23 2021-02-12 中国电子科技集团公司第三十研究所 Lightweight service interaction protocol method in tactical environment
CN112612985A (en) * 2020-12-24 2021-04-06 广州致远电子有限公司 Websocket-based multi-user and multi-type message pushing system and method

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170099332A1 (en) * 2014-03-21 2017-04-06 Ptc Inc. Systems and methods using binary dynamic rest messages
CN106209812A (en) * 2016-07-04 2016-12-07 深圳市得润车联科技有限公司 A kind of method of internet-of-things terminal platform data encapsulation
CN107835150A (en) * 2017-09-15 2018-03-23 广州唯品会研究院有限公司 A kind of full media customer service dispatching method and system
CN110875897A (en) * 2018-08-29 2020-03-10 阿里巴巴集团控股有限公司 Data transmission method, device, server and storage medium
CN112363849A (en) * 2020-10-23 2021-02-12 中国电子科技集团公司第三十研究所 Lightweight service interaction protocol method in tactical environment
CN112612985A (en) * 2020-12-24 2021-04-06 广州致远电子有限公司 Websocket-based multi-user and multi-type message pushing system and method

Also Published As

Publication number Publication date
CN113452759B (en) 2023-03-24

Similar Documents

Publication Publication Date Title
EP3803578B1 (en) Dynamic data transport between enterprise and business computing systems
US10313410B2 (en) Systems and methods using binary dynamic rest messages
CN100586109C (en) Communication method and system for universal service data based on self-defined template
CN111083161A (en) Data transmission processing method and device and Internet of things equipment
US20040068681A1 (en) Building packets of data
CN111683066A (en) Heterogeneous system integration method and device, computer equipment and storage medium
CN110620762A (en) RDMA (remote direct memory Access) -based data transmission method, network card, server and medium
CN113225320A (en) Network message analysis method for keeping user configurable message format secret
CN112787902A (en) Message encapsulation method and device and message de-encapsulation method and device
CN113452759B (en) Method and device for sending and receiving websocket communication message
US11216424B2 (en) Dynamically rendering an application programming interface for internet of things applications
CN105959263B (en) Aged caring institutions data interactive method and system based on JSON
Iglesias et al. Enabling powerful GUIs in ISOBUS networks by transparent data compression
CN111770189B (en) Networking type medical big data grading transmission method and system
CN115022413A (en) Internet of things communication protocol construction and interaction method and device
KR20180108505A (en) Method for transforming data for low volume transmission of meta model base protocol, and data transmitting system for low volume transmission of meta model base protocol
Manley et al. SPEAD: streaming protocol for exchanging astronomical data
CN113438226A (en) Message generating and analyzing method, device and system based on hybrid transmission protocol
CN112335203B (en) Processing local area network diagnostic data
CN103118023B (en) A kind of method and system of the data of transmission specification in a network
CN115152180A (en) Improved packet transmission
CN202210848U (en) System for acquiring audience information of digital television
US7586910B2 (en) Overhead reduction and address and protection in communication stack
US20100153570A1 (en) Envelope attachment for message context
CN114189565B (en) Head area restoration system, method and related equipment

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
GR01 Patent grant
GR01 Patent grant
PE01 Entry into force of the registration of the contract for pledge of patent right

Denomination of invention: Sending method, receiving method, and device for websocket communication messages

Granted publication date: 20230324

Pledgee: Guanggu Branch of Wuhan Rural Commercial Bank Co.,Ltd.

Pledgor: Wuhan dobit Information Technology Co.,Ltd.

Registration number: Y2024980010256