Communication method and device

By judging the frame type based on the opcode and end flag in the WebSocket protocol, creating a logical connection identifier cache and merging data frames, the data analysis errors and inefficiency problems in multiplexing scenarios are solved, and more efficient data analysis is achieved.

CN120378379APending Publication Date: 2025-07-25ZHEJIANG FUTURE ELF ARTIFICIAL INTELLIGENCE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510406161.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-01
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

In multiplexing scenarios, the framed operation of the WebSocket protocol leads to data parsing errors and inefficient, and lacks the association mechanism between sub-channel identifiers and framed state, which affects the accuracy and efficiency of data parsing.

Method used

Receive data frames of the WebSocket protocol through physical connections, judge the frame type based on the opcode and end flag, acquire logical connection identifiers for non-continuous frames to create a cache, add continuous frames to the cache, and merge cached data when the end flag specifies the value to ensure the correct resolution of the data frame.

Benefits of technology

It improves the accuracy and efficiency of data analysis of frame transmission in multiplexing scenarios, ensuring accurate routing and processing of data frames.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120378379A_ABST
    Figure CN120378379A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a communication method and device. A data frame of a WebSocket protocol sent by the sending end is received through physical connection, the physical connection bears multiple independent logic connections, the frame type of the data frame is determined according to the operation code, frame content is obtained from the data frame in response to the fact that the frame type is a discontinuous frame and the end mark is a second specified value, and the frame content is sent to the sending end. In response to the fact that the end mark is not a second specified value, obtaining a logic connection identifier corresponding to the data frame, creating a cache according to the logic connection identifier, in response to the fact that the frame type is a continuous frame, adding the data frame into the cache corresponding to the logic connection identifier, and in response to the fact that the end mark is the second specified value, adding the data frame into the cache corresponding to the logic connection identifier; and merging the data frames in the cache to obtain frame contents. Therefore, the data analysis accuracy and efficiency of framing transmission in a multiplexing scene can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technologies, and in particular, to a communication method and apparatus. Background Art

[0002] As a core technology in the field of real-time communication, the WebSocket protocol has become a basic protocol in many communication fields due to its low latency and full-duplex characteristics. With the complexity of application scenarios, the performance bottleneck of single connections has become increasingly prominent. Multiplexing technology, which carries multiple logical sub-channels through a single physical connection, significantly improves resource utilization and communication efficiency, and has become an important means to optimize high-concurrency scenarios.

[0003] However, when the message of a single sub-channel exceeds the frame splitting threshold, the traditional frame splitting operation will split the data into multiple consecutive frames. In a multiplexing scenario, frames of other sub-channels may be inserted into the split frame sequence, resulting in the receiving end lacking an association mechanism between the sub-channel identifier and the frame splitting state, and erroneously merging the frame data of different logical channels, leading to incorrect data parsing and low efficiency. Summary of the Invention

[0004] In view of this, the purpose of the embodiments of the present invention is to provide a communication method and apparatus, which can improve the correct rate and efficiency of data parsing for frame transmission in a multiplexing scenario.

[0005] In a first aspect, an embodiment of the present invention provides a communication method, which includes:

[0006] Receiving a data frame of the WebSocket protocol sent by a sending end through a physical connection, where the physical connection carries multiple independent logical connections;

[0007] Determining the frame type of the data frame according to the opcode, where the frame type includes a continuous frame and a discontinuous frame;

[0008] In response to the frame type being a discontinuous frame, determining whether the end flag is a second specified value. In response to the end flag being the second specified value, obtaining the frame content from the data frame. In response to the end flag not being the second specified value, obtaining the logical connection identifier corresponding to the data frame, and creating a cache according to the logical connection identifier, where the initial value of the cache is the data frame;

[0009] In response to the frame type being a continuous frame, adding the data frame to the cache corresponding to the logical connection identifier, obtaining the end flag from the data frame, and determining whether the end flag is the second specified value. In response to the end flag being the second specified value, merging the data frames in the cache to obtain the frame content.

[0010] In some embodiments, the second specified value is 1.

[0011] In some embodiments, determining the frame type of the data frame according to the opcode includes:

[0012] In response to the opcode being a first specified value, determining that the frame type of the data frame is a continuous frame;

[0013] In response to the opcode not being the first specified value, determining that the frame type of the data frame is a discontinuous frame.

[0014] In some embodiments, the first specified value is 0x0.

[0015] In a second aspect, an embodiment of the present invention provides a communication method, and the method includes:

[0016] Receiving a data frame sent by a sending end;

[0017] Obtaining an opcode from the data frame;

[0018] Determining the frame type of the data frame according to the opcode, where the frame type includes a continuous frame and a discontinuous frame;

[0019] Obtaining the frame content corresponding to the data frame according to the frame type.

[0020] In some embodiments, the data frame includes a header and payload data, the header includes at least one of an end flag, a reserved bit, an opcode, a mask, a payload length, and a mask key, and the payload data includes extended data and application data.

[0021] In some embodiments, obtaining the frame content corresponding to the data frame according to the frame type includes:

[0022] In response to the frame type being a discontinuous frame, obtaining an end flag from the data frame;

[0023] Determining whether the end flag is a second specified value;

[0024] In response to the end flag being the second specified value, obtaining the frame content from the data frame;

[0025] In response to the end flag not being the second specified value, obtaining the logical connection identifier corresponding to the data frame, and creating a cache according to the logical connection identifier, where the initial value of the cache is the data frame.

[0026] In some embodiments, obtaining the frame content corresponding to the data frame according to the frame type further includes:

[0027] In response to the frame type being a continuous frame, obtaining the logical connection identifier corresponding to the data frame;

[0028] Add the data frame to the cache corresponding to the logical connection identifier;

[0029] Obtain an end flag from the data frame;

[0030] In response to the end flag being a second specified value, merge the data frames in the cache to obtain the frame content.

[0031] In some embodiments, obtaining the logical connection identifier corresponding to the data frame includes:

[0032] Obtain the logical connection identifier from the application data, where the application data includes data to be sent and the logical connection identifier.

[0033] In a third aspect, an embodiment of the present invention provides a communication device, where the device includes:

[0034] A first receiving unit, configured to receive a data frame of the WebSocket protocol sent by a sending end through a physical connection, where the physical connection carries a plurality of independent logical connections;

[0035] A first determining unit, configured to determine the frame type of the data frame according to the opcode, where the frame type includes a continuous frame and a discontinuous frame;

[0036] A first obtaining unit, configured to, in response to the frame type being a discontinuous frame, determine whether the end flag is a second specified value, and in response to the end flag being a second specified value, obtain the frame content from the data frame, and in response to the end flag not being a second specified value, obtain the logical connection identifier corresponding to the data frame, and create a cache according to the logical connection identifier, where an initial value of the cache is the data frame;

[0037] A second obtaining unit, configured to, in response to the frame type being a continuous frame, add the data frame to the cache corresponding to the logical connection identifier, obtain an end flag from the data frame, determine whether the end flag is a second specified value, and in response to the end flag being a second specified value, merge the data frames in the cache to obtain the frame content.

[0038] In a fourth aspect, an embodiment of the present invention provides a communication device, where the device includes:

[0039] A second receiving unit, configured to receive a data frame sent by a sending end;

[0040] An opcode obtaining unit, configured to obtain an opcode from the data frame;

[0041] A frame type determining unit, configured to determine the frame type of the data frame according to the opcode, where the frame type includes a continuous frame and a discontinuous frame;

[0042] A frame content acquisition unit, configured to acquire the frame content corresponding to the data frame according to the frame type.

[0043] In a fifth aspect, an embodiment of the present invention provides an electronic device, including a memory and a processor, where the memory is used to store one or more computer program instructions, and wherein the one or more computer program instructions are executed by the processor to implement the methods described in the first aspect and the second aspect.

[0044] In a sixth aspect, an embodiment of the present invention provides a computer program product, which includes a computer program. When the computer program runs on a computer, the computer executes the methods described in the first aspect and the second aspect.

[0045] In a seventh aspect, an embodiment of the present invention provides a computer-readable storage medium, on which computer program instructions are stored, and the computer program instructions implement the methods described in the first aspect and the second aspect when executed by a processor.

[0046] The technical solution of the embodiment of the present invention receives a data frame of the WebSocket protocol sent by a sending end through a physical connection. The physical connection carries a plurality of independent logical connections. The frame type of the data frame is determined according to the opcode. In response to the frame type being a non-consecutive frame and the end flag being a second specified value, the frame content is acquired from the data frame. In response to the end flag not being the second specified value, the logical connection identifier corresponding to the data frame is acquired, and a cache is created according to the logical connection identifier. In response to the frame type being a consecutive frame, the data frame is added to the cache corresponding to the logical connection identifier. In response to the end flag being the second specified value, the data frames in the cache are merged to acquire the frame content. Thereby, the correct rate and efficiency of data parsing for frame transmission in a multiplexing scenario can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Through the following description of the embodiments of the present invention with reference to the accompanying drawings, the above and other objects, features, and advantages of the present invention will become clearer. In the drawings:

[0048] Figure 1 is a flowchart of a communication system according to an embodiment of the present invention;

[0049] Figure 2 is a flowchart of a communication method according to an embodiment of the present invention;

[0050] Figure 3 is a schematic structural diagram of a data frame according to an embodiment of the present invention;

[0051] Figure 4 is a schematic diagram of frame division according to an embodiment of the present invention;

[0052] Figure 5 It is a schematic diagram of the category of frame data in an embodiment of the present invention;

[0053] Figure 6 It is a schematic diagram of data frame transmission in an embodiment of the present invention;

[0054] Figure 7 It is a flowchart of a communication method in another embodiment of the present invention;

[0055] Figure 8 It is a schematic diagram of a communication device in an embodiment of the present invention;

[0056] Figure 9 It is a schematic diagram of a communication device in another embodiment of the present invention;

[0057] Figure 10 It is a schematic diagram of an electronic device in an embodiment of the present invention. Detailed implementation manners

[0058] The following describes the present application based on embodiments, but the present application is not limited to these embodiments. In the following detailed description of the present application, some specific details are described in detail. Those skilled in the art can fully understand the present application without the description of these details. In order to avoid obscuring the essence of the present application, well-known methods, processes, procedures, components, and circuits are not described in detail.

[0059] In addition, those of ordinary skill in the art should understand that the drawings provided herein are for illustrative purposes only, and the drawings are not necessarily drawn to scale.

[0060] Unless the context clearly requires otherwise, the words such as "including", "comprising", etc. throughout the application document shall be construed as having an inclusive meaning rather than an exclusive or exhaustive meaning; that is, it is the meaning of "including but not limited to".

[0061] In the description of the present application, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of the present application, unless otherwise specified, the meaning of "a plurality" is two or more.

[0062] For the solutions described in this specification and embodiments, if they involve personal information processing, they will all be processed on the premise of having a legal basis (such as obtaining the consent of the personal information subject, or being necessary for performing a contract, etc.), and will only be processed within the specified or agreed scope. If a user refuses to process personal information other than the necessary information required for basic functions, it will not affect the user's use of basic functions.

[0063] In the field of modern network communication, the WebSocket protocol is widely used in real-time applications due to its feature of supporting Full-Duplex communication. WebSocket provides a two-way communication channel between the client and the server through a single long connection, greatly improving the data transmission efficiency and user experience. However, with the expansion of application scenarios, especially when facing the need for transmitting large amounts of data, the fragmentation and reassembly operations of WebSocket frames become one of the common processing scenarios. WebSocket allows for the transmission of large amounts of data through multiple smaller data frames to adapt to the load limit of a single frame and efficiently transmit large message bodies. In addition, with the increasing demand for multiple concurrent streams in modern applications, the single-connection mode of WebSocket gradually reveals deficiencies in communication and processing efficiency; the introduction of multiplexing technology provides a practical and efficient optimization path for optimizing the performance of WebSocket connections.

[0064] However, although splitting large amounts of data into smaller parts is a common solution, in the multiplexing scenario, how to adapt this mechanism to ensure that each sub-channel can process data independently and efficiently while maintaining the stability and response speed of the overall system remains an urgent problem to be solved.

[0065] Figure 1 It is a flowchart of the communication system according to an embodiment of the present invention. As Figure 1 shown, the communication system according to an embodiment of the present invention includes at least one sender, at least one receiver, and a network 3. Among them, the sender can be one or more, and the receiver can also be one or more. In Figure 1 the illustrated embodiment, a communication system including n senders 1a, 1b,..., 1n and including one receiver 2 is taken as an example for illustration.

[0066] Among them, one of the sender and the receiver is a client, and the other is a server. That is, if the sender is a client, the receiver is a server; if the sender is a server, the receiver is a client. Among them, the client can be a smart speaker, a mobile phone, a tablet computer, a laptop computer, a desktop computer, an embedded system, etc.; the server can be a single server or a server cluster composed of multiple servers.

[0067] In this embodiment, at least one sender and at least one receiver are connected through network 3. Among them, network 3 is a communication network based on the WebSocket (Web Socket) protocol. The communication network of the WebSocket (Web Socket) protocol supports full-duplex communication, allowing real-time data exchange between the sender and the receiver without frequently initiating new connection requests. After a handshake process of the WebSocket protocol, a persistent TCP (Transmission Control Protocol) connection is established, thereby reducing the latency and overhead in the traditional HTTP (Hypertext Transfer Protocol) request-response mode.

[0068] Among them, the handshake process of the WebSocket protocol is built on top of the HTTP protocol, and the connection is upgraded to the WebSocket protocol through an initial HTTP request and response. Specifically, the client is the party that initiates the WebSocket connection request, usually used for real-time data exchange with the server. The server is the party that responds to the client's request and maintains the WebSocket connection, responsible for processing data streams from multiple clients and providing necessary services and support. Specifically, the client sends an HTTP upgrade request to the server. The HTTP upgrade request includes specific HTTP header information, which is used to instruct the server to upgrade the current HTTP connection to a WebSocket connection. The server responds to the client's upgrade request. If the server supports the WebSocket protocol and is willing to accept this upgrade, it will return a response with a specific status code indicating agreement to switch the protocol. Once the handshake is successfully completed, the TCP connection is upgraded to a WebSocket connection. At this time, the client and the server can perform full-duplex communication through this connection without having to initiate new HTTP requests, and both parties can start sending and receiving data frames through the WebSocket channel.

[0069] Figure 2 is a flowchart of the communication method according to an embodiment of the present invention. As Figure 2 shown, the communication method according to the embodiment of the present invention includes the following steps:

[0070] Step S110: Receive a data frame of the WebSocket (Web Socket) protocol sent by the sending end through a physical connection.

[0071] In this embodiment, the two parties of the interaction normally establish a multiplexed long connection based on WebSocket, and based on this connection, the receiver receives the data frame of the WebSocket (Web Socket) protocol from the sender. Among them, the physical connection carries multiple independent logical connections.

[0072] Figure 3 It is a schematic structural diagram of a data frame according to an embodiment of the present invention. As Figure 3 shown, the data frame according to the embodiment of the present invention is a WebSocket frame, including a header and payload data. Among them, the header includes at least one of an end flag, reserved bits, an opcode, a mask, a payload length, and a mask key, and the payload data includes extension data and application data.

[0073] End flag (FIN), indicating whether the current frame is the last frame of the message. When the end flag is 0, it indicates that the current frame is not the last frame; when the end flag is 1, it indicates that the current frame is the last frame.

[0074] Reserved bits (RSV1, RSV2, RSV3), used for protocol extension, and should be set to 0 by default, unless a specific protocol extension defines the meaning of non-zero values.

[0075] Opcode, a frame type identifier, used to distinguish different types of frames. For example, the opcode of a text frame (TextFrame) = 0x1, used to transmit text strings. The opcode of a binary frame (Binary Frame) = 0x2, used to transmit binary data, such as images or files. The opcode of a continuation frame = 0x0, used to transmit subsequent frames in a segmented data stream until the message ends. The opcode of a connection close frame = 0x8, used to terminate the connection. The opcodes of Ping frame and Pong frame = 0x9 and 0xA, used for connection liveness detection.

[0076] Mask (MASK), used to indicate whether the payload data is masked.

[0077] Payload length (Payload len), indicating the length of the payload data. Depending on different values, it may directly represent the length or indicate how many bytes follow to represent the actual length. The size of the payload length is 7 bits (i.e., the lower 7 bits in 1 byte). If the length of the payload data is between 0 and 125 bytes, these 7 bits are directly used to represent the actual length.

[0078] The trigger condition for the extended payload length is when Payload len = 126 or 127. If payload len = 126, the next 2 bytes (16 bits) represent the extended payload length, and the range that can be represented is from 126 to 2 16-1 (i.e., 65535) bytes. If payload len = 127, the next 8 bytes (64 bits) represent the extended payload length, and the range that can be represented is from 2 16 to 2 64 -1 bytes, and in this case, it can support an extremely large amount of data. For "Extended payload length continued" in the figure, it is not a separately existing field. When payload len equals 127, there will be an additional 8 bytes to represent the actual payload length. Here, "continued" means that in these 8 bytes, all bytes are used together to represent a part of a complete 64-bit unsigned integer value.

[0079] Masking-key: Exists when the Mask bit is set and is used to decode the payload data to increase security. This key is only required for client-to-server messages.

[0080] Payload data: Consists of Extension data and Application data. This is the actual content part of the frame and contains the data to be transmitted.

[0081] Extension data: By default, it is not used unless certain protocol extensions are enabled through negotiation.

[0082] Application data: The part of the application layer data actually carried in the frame, which comes after the "Extension data" and occupies the remaining part of the frame.

[0083] The WebSocket protocol allows large data volume messages to be transmitted through multiple smaller data frames, so as to efficiently transmit large message bodies without exceeding the payload limit of a single frame. The specific steps are as follows:

[0084] Message splitting: For large data volume message bodies such as video streams and file transfers, first, they need to be split from the application data layer into multiple small segments. The splitting strategy needs to ensure that the size of each segment adapts to the payload capacity of a single WebSocket frame.

[0085] First frame transmission: A text frame or a binary frame is used as the first frame to transmit the message, and the opcode is set to distinguish the data type. It is necessary to identify the start of the message segment, and the FIN bit of the first frame is set to 0, indicating that there are more frames to follow.

[0086] Use of consecutive frames: For the remaining message segments, they are transmitted through consecutive frames until the last message segment. The continuous intermediate frames keep the FIN bit as 0 until the termination frame sets the FIN bit to 1, indicating the end of the current message.

[0087] Figure 4 It is a schematic diagram of frame division according to an embodiment of the present invention. As Figure 4 shown, the upper text frame A is the original data frame, including a header and a payload. Only the opcode and FIN in the header are shown in the figure, and the payload is the payload data shown above. Among them, the opcode is 0x1, indicating that the type of this data frame is a text frame, and FIN is 1, indicating that this data frame is the last frame. That is, for an unframed single data frame, FIN is 1. The payload is greater than 64KB.

[0088] Assume that the responsible content is limited to 64KB, then the original text frame needs to be framed. After framing, the original data frame is divided into multiple data frames, including a first frame, intermediate frames, and a last frame. If it is only divided into two data frames, there is no intermediate frame.

[0089] For the first frame B1, the opcode is 0x1, indicating that the type of this data frame is a text frame, and FIN is 0, indicating that this data frame is not the last frame.

[0090] For the intermediate frames B2 - B N-1 , the opcode is 0x0, indicating that the type of this data frame is a consecutive frame, and FIN is 0, indicating that this data frame is not the last frame.

[0091] For the last frame B N , the opcode is 0x0, indicating that the type of this data frame is a consecutive frame, and FIN is 1, indicating that this data frame is the last frame.

[0092] Figure 5 It is a schematic diagram of the category of frame data according to an embodiment of the present invention. As Figure 5 shown, the embodiments of the present invention can divide the category of data frames into four types, namely single frame, first frame of framed data, intermediate frame of framed data, and last frame of framed data. The values of FIN and opcode corresponding to each category are shown in the figure. It should be noted that Figure 5 in the shown embodiment, the text frame is taken as an example for illustration. If it is other types of frames, the 0x1 therein needs to be replaced with the corresponding value of the type.

[0093] Figure 6 It is a schematic diagram of data frame transmission according to an embodiment of the present invention. As Figure 6As shown, the data frame is sent from the sender to the receiver. Among them, the sender has multiple logical channels, and the multiple logical channels can transmit data separately. The data of the multiple logical channels is finally sent to the receiver through a physical channel.

[0094] Among them, a physical connection refers to a connection actually established at the network level. In WebSocket, it refers to a specific TCP connection from the sender to the receiver, and this connection is upgraded to a WebSocket connection through a handshake process. The physical connection is usually persistent. In WebSocket, once established, it will remain open until one party closes the connection. It provides the ability for two-way communication, allowing the sender and the receiver to send data at any time. At the network level, each physical connection consumes a certain amount of system resources, such as file descriptors, memory, etc.

[0095] A logical connection is a concept defined at the application level and is used to simulate multiple independent data transmission channels on the same physical connection. These logical connections are not real network connections, but rather distinguish different data streams through a certain method (such as adding identifiers) for separate processing. A logical connection allows multiple types of data exchanges to occur simultaneously on the same physical connection, such as different types of messages or messages from different subsystems. Each logical connection can have its own state management and message serialization / deserialization rules. By adding specific identifiers to the messages, the mixed data streams can be correctly separated at the receiver according to these identifiers and routed to the corresponding application logic parts.

[0096] Multiplexing technology uses a single physical connection to support multiple logical connections, thereby improving efficiency and reducing resource consumption.

[0097] Among them, the multiple logical connections can belong to different devices or the same device, and can be configured according to the actual application scenario.

[0098] For multiple logical connections in the same device, they can be message streams from the same device. Taking the smart speaker scenario as an example, assume that the smart speaker has multiple functions, such as a voice assistant, smart home control, music playback, etc. These functions may need to manage their respective message streams through different logical connections to more efficiently process different types of data updates and requests.

[0099] For logical connections between different devices, for example, in a smart home environment, multiple smart devices (including but not limited to smart speakers) may communicate with the Internet through the same WebSocket server. Although these devices share the same physical connection or gateway resources, the communication of each device can be regarded as an independent logical connection.

[0100] Meanwhile, one of the sender and the receiver is a server, and the other is a client.

[0101] When the sender is the client and the receiver is the server, the client can distinguish different logical connections or message types by adding a logical connection identifier to a part of the data frame being sent. In this way, even if all data is sent through the same WebSocket connection, the server can correctly route and process these messages based on the logical connection identifier.

[0102] When the sender is the server and the receiver is the client, the server can construct messages containing logical connection identifiers and send these messages to the client through a single WebSocket connection. After receiving the messages, the client can identify and process the corresponding messages based on the logical connection identifier.

[0103] In Figure 6 the illustrated embodiment, taking an example where one physical channel P supports three logical channels L1 - L3 for explanation.

[0104] Among them, the data to be sent by logical channel L1 includes C1 and C2. Among them, C1 does not exceed the load limit, and C2 exceeds the load limit. Therefore, C1 does not need to be framed and can be directly transmitted. C2 needs to be framed. In the embodiment of the present invention, after framing, C 2,1 、C 2,2 、C 2,3 .

[0105] The data to be sent by logical channel L2 includes D1 and D2. Among them, D1 does not exceed the load limit, and D2 exceeds the load limit. Therefore, D1 does not need to be framed and can be directly transmitted. D2 needs to be framed. In the embodiment of the present invention, after framing, D 2,1 、D 2,2 .

[0106] The data to be sent by logical channel L3 includes E1 and E2. Among them, both E1 and E2 do not exceed the load limit and do not need to be framed and can be directly transmitted.

[0107] Furthermore, when generating a data frame, the sender needs to add a logical connection identifier to the data frame. Specifically, add a logical connection identifier to the data frame to be sent, encapsulate the logical connection identifier into the application data together, and use the WebSocket API to send the encapsulated data frame.

[0108] In Figure 6 the illustrated embodiment, the data frames sent by physical channel P include 9, which are in sequence:

[0109] Message M1: C1;

[0110] Message M2: D1;

[0111] Message M3: C 2,1 ;

[0112] Message M4: D 2,1 ;

[0113] Message M5: C 2,2 ;

[0114] Message M6: E1;

[0115] Message M7: D 2,2 ;

[0116] Message M8: C 2,3 ;

[0117] Message M9: E2.

[0118] Thus, the receiver receives the data frames sent by the sender through the physical channel.

[0119] It should be noted that when the sender sends data, it needs to send the data frames in the order of time. That is, for multiple sub-frames of the same data, their order cannot be reversed. Taking the above 9 messages as an example, among them, messages M3, M5, and M8 are multiple sub-frames of the same data, and their time order is consistent with the sub-frame order.

[0120] Step S120, detect whether the data frame is a continuous frame.

[0121] In this embodiment, according to the operation code, the frame type of the data frame is determined, and the frame type includes a continuous frame and a non-continuous frame. Specifically, the receiver processes the received data frames in sequence. Assuming that the received data frames are messages M1 - M9 in sequence, then starting from message M1, each received data frame is processed one by one.

[0122] For the data frame to be processed, parse the data frame to obtain the operation code, and determine the frame type of the data frame according to the operation code. In response to the operation code being the first specified value, determine that the frame type of the data frame is a continuous frame. In response to the operation code not being the first specified value, determine that the frame type of the data frame is a non-continuous frame. Combining Figure 5 it can be known that the first specified value is 0x0.

[0123] In response to the frame type being a non-continuous frame, enter step S130.

[0124] In response to the frame type being a continuous frame, enter step S160.

[0125] Step S130: Detect whether the end flag is the second specified value.

[0126] In this embodiment, in combination with Figure 5 , when the frame type is a discontinuous frame, the data frame may be a single frame or the first frame of a fragmented frame. Therefore, further judgment is required. Specifically, parse the data frame to obtain the end flag, and detect whether the end flag is the second specified value, where the second specified value is 1.

[0127] In response to the end flag being the second specified value, determine that the data frame is a single frame, and enter step S140.

[0128] In response to the end flag not being the second specified value, determine that the data frame is the first frame of a fragmented frame, and enter step S150.

[0129] Step S140: Obtain the frame content from the data frame.

[0130] In this embodiment, in response to the end flag being the second specified value, determine that the data frame is a single frame, that is, the data in this data frame includes all the information to be sent and does not require frame combination, and the frame content can be directly obtained from the data frame.

[0131] Among them, obtaining the frame content from the data frame includes parsing the data frame to obtain payload data, and the payload data includes extension data and application data. Obtain the application data therein, and the application data includes the data to be sent and the logical connection identifier. Thus, the receiving party can determine the logical channel of the sending party according to the logical connection identifier, and determine the frame content according to the data to be sent, and the frame content is the communication content.

[0132] Step S150: Obtain the logical connection identifier corresponding to the data frame, and create a cache according to the logical connection identifier.

[0133] In this embodiment, in response to the end flag not being the second specified value, determine that the data frame is the first frame of a fragmented frame, that is, the data in this data frame only includes part of the information to be sent, and all the fragmented frames associated with this data frame need to be obtained before processing. Thus, obtain the logical connection identifier corresponding to the data frame, and create a cache according to the logical connection identifier. The initial value of the cache is the data frame.

[0134] Specifically, obtain the application data from the data frame, and obtain the logical connection identifier from the application data. Create a cache according to the logical connection identifier, and the created cache corresponds to the logical connection identifier. At the same time, add this data frame as the initial value to the created cache.

[0135] Step S160: Add the data frame to the cache corresponding to the logical connection identifier.

[0136] In this embodiment, in response to the frame type being a continuous frame, parse the data frame to obtain application data, obtain the logical connection identifier from the application data, determine the corresponding cache according to the obtained logical connection identifier, and add the data frame to the cache corresponding to the logical connection identifier.

[0137] Furthermore, combined with Figure 5 it can be known that when the opcode is 0x0, it indicates that the data frame is a continuous frame. At this time, the data frame may be an intermediate frame or a tail frame of a fragmented frame. Therefore, further judgment is required.

[0138] Step S170: Detect whether the end flag is a second specified value.

[0139] In this embodiment, parse the data frame to obtain the end flag, and determine whether the end flag is a second specified value. The second specified value is 1.

[0140] In response to the end flag being the second specified value, determine that the data frame is the tail frame of the fragmented frame, and enter step S180.

[0141] In response to the end flag not being the second specified value, determine that the data frame is an intermediate frame of the fragmented frame. At this time, there is no need to obtain the frame content, and start processing the next data frame.

[0142] Step S180: Merge the data frames in the cache to obtain the frame content.

[0143] In response to the end flag being the second specified value, determine that the data frame is the tail frame of the fragmented frame, indicating that the information of this fragmented frame has been received completely. Add the data frame to the cache corresponding to the logical connection identifier. At the same time, obtain all the data frames in this cache, and merge the data frames in the cache to obtain the frame content.

[0144] Specifically, combined with Figure 6 , after the receiving party receives the data frame, determine the logical connection identifier corresponding to each data frame through multiplexing parsing, and then determine the logical channel corresponding to each data frame. Then, through frame combination, multiple fragmented frames of the same logical channel are combined to obtain the final frame content.

[0145] Take Figure 6 as an example for illustration. The data frames received by the receiving party through the physical channel P are as follows:

[0146] Message M1: C1;

[0147] Message M2: D1;

[0148] Message M3: C 2,1 ;

[0149] Message M4: D 2,1 ;

[0150] Message M5: C 2,2 ;

[0151] Message M6: E1;

[0152] Message M7: D 2,2 ;

[0153] Message M8: C 2,3 ;

[0154] Message M9: E2.

[0155] Among them, the parameter groups (operation code, end flag, logical connection) corresponding to Messages M1 - M9 are respectively:

[0156] Message M1: (0x1, 1, L1);

[0157] Message M2: (0x1, 1, L2);

[0158] Message M3: (0x1, 0, L1);

[0159] Message M4: (0x1, 0, L2);

[0160] Message M5: (0x0, 0, L1);

[0161] Message M6: (0x1, 1, L3);

[0162] Message M7: (0x0, 1, L2);

[0163] Message M8: (0x0, 1, L1);

[0164] Message M9: (0x1, 1, L3).

[0165] Process each data frame in sequence, and the results are as follows:

[0166] For Message M1, after parsing and determination, Message M1 is a non - continuous frame, and the end flag is 1, indicating that Message M1 is a single frame. Therefore, through step S140, the frame content is obtained from the data frame.

[0167] For Message M2, after parsing and determination, Message M2 is a non - continuous frame, and the end flag is 1, indicating that Message M2 is a single frame. Therefore, through step S140, the frame content is obtained from the data frame.

[0168] For message M3, after parsing and determination, it is found that message M3 is a discontinuous frame and the end flag is 0, indicating that message M3 is the first frame of a segmented frame. Therefore, through step S150, the logical connection identifier corresponding to the data frame is obtained, and a cache is created according to the logical connection identifier. That is, a cache for logical channel L1 is created.

[0169] For message M4, after parsing and determination, it is found that message M4 is a discontinuous frame and the end flag is 0, indicating that message M4 is the first frame of a segmented frame. Therefore, through step S150, the logical connection identifier corresponding to the data frame is obtained, and a cache is created according to the logical connection identifier. That is, a cache for logical channel L2 is created.

[0170] For message M5, after parsing and determination, it is found that message M5 is a continuous frame and the end flag is 0, indicating that message M5 is an intermediate frame of a segmented frame. Therefore, through step S160, the data frame is added to the cache corresponding to the logical connection identifier. That is, message M5 is added to the cache of logical channel L1 created when processing message M3.

[0171] For message M6, after parsing and determination, it is found that message M6 is a discontinuous frame and the end flag is 1, indicating that message M6 is a single frame. Therefore, through step S140, the frame content is obtained from the data frame.

[0172] For message M7, after parsing and determination, it is found that message M7 is a continuous frame and the end flag is 1, indicating that message M7 is the last frame of a segmented frame. Therefore, through step S160, the data frame is added to the cache corresponding to the logical connection identifier. Then, through step S180, the data frames in the cache are merged to obtain the frame content. That is, message M7 is added to the cache of logical channel L2 created when processing message M4. At this time, the cache includes message M4 and message M7, and message M4 and message M7 are merged to obtain the frame content.

[0173] For message M8, after parsing and determination, it is found that message M8 is a continuous frame and the end flag is 1, indicating that message M8 is the last frame of a segmented frame. Therefore, through step S160, the data frame is added to the cache corresponding to the logical connection identifier. Then, through step S180, the data frames in the cache are merged to obtain the frame content. That is, message M8 is added to the cache of logical channel L1 created when processing message M3. At this time, the cache includes message M3, message M5 and message M8, and message M3, message M5 and message M8 are merged to obtain the frame content.

[0174] For message M9, after parsing and determination, it is found that message M9 is a discontinuous frame and the end flag is 1, indicating that message M9 is a single frame. Therefore, through step S140, the frame content is obtained from the data frame.

[0175] Thus, through the above content, the data frame can be correctly parsed.

[0176] In an embodiment of the present invention, a data frame of the WebSocket protocol sent by a sending end is received through a physical connection. The physical connection carries multiple independent logical connections. The frame type of the data frame is determined according to an opcode. In response to the frame type being a non - continuous frame and the end flag being a second specified value, the frame content is obtained from the data frame. In response to the end flag not being the second specified value, the logical connection identifier corresponding to the data frame is obtained, and a cache is created according to the logical connection identifier. In response to the frame type being a continuous frame, the data frame is added to the cache corresponding to the logical connection identifier. In response to the end flag being the second specified value, the data frames in the cache are merged to obtain the frame content. Thus, the correct parsing rate and efficiency of the fragmented transmission in a multiplexing scenario can be improved.

[0177] Figure 7 It is a flowchart of a communication method according to another embodiment of the present invention. As Figure 7 shown, the communication method according to an embodiment of the present invention includes the following steps:

[0178] Step S210: Receive a data frame sent by a sending end.

[0179] Step S220: Obtain an opcode from the data frame.

[0180] Step S230: Determine the frame type of the data frame according to the opcode. The frame type includes a continuous frame and a non - continuous frame.

[0181] Step S240: Obtain the frame content corresponding to the data frame according to the frame type.

[0182] In some embodiments, the data frame includes a header and payload data. The header includes at least one of an end flag, a reserved bit, an opcode, a mask, a payload length, and a mask key. The payload data includes extension data and application data.

[0183] In some embodiments, the obtaining the frame content corresponding to the data frame according to the frame type includes:

[0184] In response to the frame type being a non - continuous frame, obtain an end flag from the data frame;

[0185] Judge whether the end flag is the second specified value;

[0186] In response to the end flag being the second specified value, obtain the frame content from the data frame;

[0187] In response to the end flag not being the second specified value, obtain the logical connection identifier corresponding to the data frame, and create a cache according to the logical connection identifier, where the initial value of the cache is the data frame.

[0188] In some embodiments, the obtaining the frame content corresponding to the data frame according to the frame type further includes:

[0189] In response to the frame type being a continuous frame, obtain the logical connection identifier corresponding to the data frame;

[0190] Add the data frame to the cache corresponding to the logical connection identifier;

[0191] Obtain the end flag from the data frame;

[0192] In response to the end flag being the second specified value, merge the data frames in the cache to obtain the frame content.

[0193] In some embodiments, the obtaining the logical connection identifier corresponding to the data frame includes:

[0194] Obtain the logical connection identifier from the application data, where the application data includes the data to be sent and the logical connection identifier.

[0195] In an embodiment of the present invention, a data frame of the WebSocket protocol sent by a sending end is received through a physical connection. The physical connection carries multiple independent logical connections. The frame type of the data frame is determined according to the opcode. In response to the frame type being a non - continuous frame and the end flag being the second specified value, the frame content is obtained from the data frame. In response to the end flag not being the second specified value, the logical connection identifier corresponding to the data frame is obtained, and a cache is created according to the logical connection identifier. In response to the frame type being a continuous frame, the data frame is added to the cache corresponding to the logical connection identifier. In response to the end flag being the second specified value, the data frames in the cache are merged to obtain the frame content. Thereby, the correct rate and efficiency of data parsing for frame - by - frame transmission in a multiplexing scenario can be improved.

[0196] Figure 8 is a schematic diagram of a communication device according to an embodiment of the present invention. As Figure 8As shown in the figure, the communication device according to an embodiment of the present invention includes a first receiving unit 81, a first determining unit 82, a first obtaining unit 83, and a second obtaining unit 84. Among them, the first receiving unit 81 is configured to receive a data frame of the WebSocket protocol sent by a sending end through a physical connection, and the physical connection carries a plurality of independent logical connections. The first determining unit 82 is configured to determine the frame type of the data frame according to the opcode, and the frame type includes a continuous frame and a discontinuous frame. The first obtaining unit 83 is configured to, in response to the frame type being a discontinuous frame, determine whether the end flag is a second specified value. In response to the end flag being the second specified value, obtain the frame content from the data frame. In response to the end flag not being the second specified value, obtain the logical connection identifier corresponding to the data frame, and create a cache according to the logical connection identifier, and the initial value of the cache is the data frame. The second obtaining unit 84 is configured to, in response to the frame type being a continuous frame, add the data frame to the cache corresponding to the logical connection identifier, obtain the end flag from the data frame, determine whether the end flag is the second specified value, and in response to the end flag being the second specified value, merge the data frames in the cache to obtain the frame content.

[0197] In an embodiment of the present invention, a data frame of the WebSocket protocol sent by a sending end is received through a physical connection, and the physical connection carries a plurality of independent logical connections. The frame type of the data frame is determined according to the opcode. In response to the frame type being a discontinuous frame and the end flag being a second specified value, the frame content is obtained from the data frame. In response to the end flag not being the second specified value, the logical connection identifier corresponding to the data frame is obtained, and a cache is created according to the logical connection identifier. In response to the frame type being a continuous frame, the data frame is added to the cache corresponding to the logical connection identifier. In response to the end flag being the second specified value, the data frames in the cache are merged to obtain the frame content. Thereby, the correct rate and efficiency of data parsing for framed transmission in a multiplexing scenario can be improved.

[0198] Figure 9 It is a schematic diagram of a communication device according to another embodiment of the present invention. As Figure 9 shown in the figure, the communication device according to an embodiment of the present invention includes a second receiving unit 91, an opcode obtaining unit 92, a frame type determining unit 93, and a frame content obtaining unit 94. Among them, the second receiving unit 91 is configured to receive a data frame sent by a sending end. The opcode obtaining unit 92 is configured to obtain the opcode from the data frame. The frame type determining unit 93 is configured to determine the frame type of the data frame according to the opcode, and the frame type includes a continuous frame and a discontinuous frame. The frame content obtaining unit 94 is configured to obtain the frame content corresponding to the data frame according to the frame type.

[0199] In an embodiment of the present invention, a data frame of the WebSocket protocol sent by a sending end is received through a physical connection. The physical connection carries multiple independent logical connections. The frame type of the data frame is determined according to an opcode. In response to the frame type being a non - continuous frame and the end flag being a second specified value, the frame content is obtained from the data frame. In response to the end flag not being the second specified value, the logical connection identifier corresponding to the data frame is obtained, and a cache is created according to the logical connection identifier. In response to the frame type being a continuous frame, the data frame is added to the cache corresponding to the logical connection identifier. In response to the end flag being the second specified value, the data frames in the cache are merged to obtain the frame content. Thus, the correct rate and efficiency of data parsing for framed transmission in a multiplexing scenario can be improved.

[0200] Figure 10 FIG. is a schematic diagram of an electronic device according to an embodiment of the present invention. In this embodiment, the electronic device 10 includes a server, a terminal, etc. As Figure 10 shown, the electronic device 10: includes at least one processor 101; and, a memory 102 communicatively connected to at least one processor 101; and, a communication component 103 communicatively connected to a scanning device. The communication component 103 receives and sends data under the control of the processor 101. Among them, the memory 102 stores instructions executable by at least one processor 101, and the instructions are executed by at least one processor 101 to implement the above - mentioned communication method.

[0201] Specifically, the electronic device includes: one or more processors 101 and a memory 102. Figure 10 Here, one processor 101 is taken as an example. The processor 101 and the memory 102 can be connected through a bus or other means. Figure 10 Here, taking the connection through a bus as an example. The memory 102, as a non - volatile computer - readable storage medium, can be used to store non - volatile software programs, non - volatile computer - executable programs, and modules. The processor 101 executes various functional applications and data processing of the device by running the non - volatile software programs, instructions, and modules stored in the memory 102, that is, to implement the above - mentioned communication method.

[0202] The memory 102 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store an option list, etc. In addition, the memory 102 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some embodiments, the memory 102 may optionally include a memory remotely provided relative to the processor 101, and these remote memories can be connected to external devices through a network. Examples of the above network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0203] One or more modules are stored in the memory 102 and, when executed by one or more processors 101, execute the communication method in any of the above method embodiments.

[0204] The above product can execute the method provided in the embodiments of the present application, and has the corresponding functional modules and beneficial effects of the executed method. For technical details not described in detail in this embodiment, reference can be made to the method provided in the embodiments of the present application.

[0205] In an embodiment of the present invention, a data frame of the WebSocket protocol sent by a sending end is received through a physical connection. The physical connection carries a plurality of independent logical connections. The frame type of the data frame is determined according to an opcode. In response to the frame type being a non-consecutive frame and the end flag being a second specified value, the frame content is obtained from the data frame. In response to the end flag not being the second specified value, the logical connection identifier corresponding to the data frame is obtained, and a cache is created according to the logical connection identifier. In response to the frame type being a consecutive frame, the data frame is added to the cache corresponding to the logical connection identifier. In response to the end flag being the second specified value, the data frames in the cache are merged to obtain the frame content. Thus, the correct rate and efficiency of data parsing for frame transmission in a multiplexing scenario can be improved.

[0206] Another embodiment of the present invention relates to a non-volatile storage medium for storing a computer-readable program, and the computer-readable program is used for a computer to execute some or all of the above method embodiments.

[0207] That is, those skilled in the art can understand that all or part of the steps in the methods of the above embodiments can be completed by instructing relevant hardware through a program. The program is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, a chip, etc.) or a processor to execute all or part of the steps of the methods described in the embodiments of the present application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs.

[0208] The foregoing are only the preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the protection scope of the present application.

Claims

1. A communication method, characterized in that, The method includes: Receiving a data frame of the WebSocket protocol sent by a sending end through a physical connection, where the physical connection carries multiple independent logical connections; Determining the frame type of the data frame according to an opcode, where the frame type includes a continuous frame and a discontinuous frame; In response to the frame type being a discontinuous frame, determining whether an end flag is a second specified value. In response to the end flag being the second specified value, obtaining frame content from the data frame. In response to the end flag not being the second specified value, obtaining a logical connection identifier corresponding to the data frame, and creating a cache according to the logical connection identifier, where an initial value of the cache is the data frame; In response to the frame type being a continuous frame, adding the data frame to a cache corresponding to a logical connection identifier, obtaining an end flag from the data frame, determining whether the end flag is the second specified value, and in response to the end flag being the second specified value, merging data frames in the cache to obtain the frame content.

2. The method according to claim 1, characterized in that, The second specified value is 1.

3. The method according to claim 1, wherein The determining the frame type of the data frame according to the opcode includes: In response to the opcode being a first specified value, determining that the frame type of the data frame is a continuous frame; In response to the opcode not being the first specified value, determining that the frame type of the data frame is a discontinuous frame.

4. The method according to claim 3, wherein The first specified value is 0x0.

5. A communication method, characterized in that, The method includes: Receiving a data frame sent by a sending end; Obtaining an opcode from the data frame; Determining the frame type of the data frame according to the opcode, where the frame type includes a continuous frame and a discontinuous frame; Obtaining frame content corresponding to the data frame according to the frame type.

6. The method according to claim 5, characterized in that, The data frame includes a header and payload data, where the header includes at least one of an end flag, a reserved bit, an opcode, a mask, a payload length, and a mask key, and the payload data includes extended data and application data.

7. The method according to claim 6, characterized in that, The obtaining frame content corresponding to the data frame according to the frame type includes: In response to the frame type being a discontinuous frame, obtaining an end flag from the data frame; Determining whether the end flag is the second specified value; In response to the end flag being the second specified value, obtaining frame content from the data frame; In response to the end flag not being the second specified value, obtaining a logical connection identifier corresponding to the data frame, and creating a cache according to the logical connection identifier, where an initial value of the cache is the data frame.

8. The method according to claim 7, wherein The obtaining frame content corresponding to the data frame according to the frame type further includes: In response to the frame type being a continuous frame, obtaining a logical connection identifier corresponding to the data frame; Adding the data frame to a cache corresponding to the logical connection identifier; Obtaining an end flag from the data frame; In response to the end flag being the second specified value, merging data frames in the cache to obtain the frame content.

9. The method according to claim 7 or 8, characterized in that The obtaining the logical connection identifier corresponding to the data frame includes: Obtaining the logical connection identifier from the application data, where the application data includes data to be sent and the logical connection identifier.

10. A communication device, characterized in that, The device includes: A first receiving unit, configured to receive a data frame of a WebSocket protocol sent by a sending end through a physical connection, where the physical connection carries a plurality of independent logical connections; A first determining unit, configured to determine a frame type of the data frame according to an opcode, where the frame type includes a continuous frame and a discontinuous frame; A first obtaining unit, configured to, in response to the frame type being a discontinuous frame, determine whether an end flag is a second specified value, and in response to the end flag being the second specified value, obtain frame content from the data frame, and in response to the end flag not being the second specified value, obtain a logical connection identifier corresponding to the data frame, and create a cache according to the logical connection identifier, where an initial value of the cache is the data frame; A second obtaining unit, configured to, in response to the frame type being a continuous frame, add the data frame to a cache corresponding to a logical connection identifier, obtain an end flag from the data frame, determine whether the end flag is the second specified value, and in response to the end flag being the second specified value, merge data frames in the cache to obtain the frame content.

11. A communication device, characterized in that, The apparatus includes: A second receiving unit, configured to receive a data frame sent by a sending end; An opcode obtaining unit, configured to obtain an opcode from the data frame; A frame type determining unit, configured to determine a frame type of the data frame according to the opcode, where the frame type includes a continuous frame and a discontinuous frame; A frame content obtaining unit, configured to obtain frame content corresponding to the data frame according to the frame type.

12. An electronic device, comprising a memory and a processor, characterized in that, The memory is configured to store one or more computer program instructions, where the one or more computer program instructions are executed by the processor to implement the method according to any one of claims 1-9.

13. A computer program product, the computer program product comprising a computer program, characterized in that, When the computer program runs on a computer, the computer executes the method according to any one of claims 1-9.

14. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, The computer program instructions, when executed by a processor, implement the method according to any one of claims 1-9.