A data exchange method, device and medium for a web application

By using WebSocket connections and data-driven typed array view processing, the inefficiency of the HTTP 1.X protocol is solved, enabling efficient data exchange and real-time response for web applications.

CN116668424BActive Publication Date: 2026-04-24浪潮智慧科技有限公司
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
浪潮智慧科技有限公司
Filing Date
2023-06-27
Publication Date
2026-04-24

AI Technical Summary

Technical Problem

The existing HTTP 1.X protocol is inefficient in transmitting data and cannot meet the high real-time requirements of scenarios such as instant messaging, resulting in low data exchange efficiency for web applications.

Method used

It uses the WebSocket protocol to establish a connection with the web application client, receives and parses binary data exchange requests, stores data in a pre-created contiguous memory area, and performs formatting processing based on the data volume to determine the view type of the typed array, thereby improving data exchange efficiency.

Benefits of technology

It improves the responsiveness and data exchange efficiency of web applications, supports real-time data exchange, and enhances the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116668424B_ABST
    Figure CN116668424B_ABST
Patent Text Reader

Abstract

The application discloses a data exchange method and device for a web application, and a medium. The method comprises the following steps: establishing a websocket protocol connection with a web application client; receiving a data exchange request of the web application client, analyzing the data exchange request, and obtaining to-be-analyzed data exchange content; the to-be-analyzed data exchange content is encoded data of binary data; storing the to-be-analyzed data exchange content according to a pre-created continuous memory area for storing binary data; determining a view type of a typed array of the to-be-analyzed data exchange content according to a data amount of the to-be-analyzed data exchange content, formatting the to-be-analyzed data exchange content in the continuous memory area through the view type, and obtaining a signed integer array; and accessing the signed integer array, and analyzing to obtain binary exchange data of the to-be-analyzed data exchange content. The data exchange efficiency for the web application can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a data exchange method, device and medium for web applications. Background Technology

[0002] The HTTP 1.X protocol is text-based during data transmission. The inherent limitations of text-based protocol format parsing result in a limited amount of data that can be transmitted. Furthermore, the HTTP protocol operates on a request-response model, where the client sends an HTTP request and the server returns an HTTP response. While this model is sufficient for loading resources and data, it cannot efficiently facilitate data exchange between the client and server in scenarios with high real-time requirements, such as instant messaging. Consequently, it leads to low data exchange efficiency for web applications. Summary of the Invention

[0003] This application provides a data exchange method, device, and medium for web applications to solve the problem of low data exchange efficiency for web applications.

[0004] The embodiments of this application adopt the following technical solutions:

[0005] On one hand, embodiments of this application provide a data exchange method for a web application. The method includes: establishing a WebSocket protocol connection with a web application client; receiving a data exchange request from the web application client; parsing the data exchange request to obtain data exchange content to be parsed; the data exchange content to be parsed is encoded binary data; storing the data exchange content to be parsed according to a pre-created contiguous memory region for storing binary data; determining a view type of a typed array of the data exchange content to be parsed based on the data volume of the data exchange content to be parsed; formatting the data exchange content to be parsed in the contiguous memory region using the view type to obtain a signed integer array; and accessing the signed integer array to parse and obtain the binary exchange data of the data exchange content to be parsed.

[0006] In one example, storing the data exchange content to be parsed based on a pre-created contiguous memory region for storing binary data specifically includes: determining a pre-created first contiguous memory region for storing binary data and its storage capacity; comparing the storage capacity with the amount of data in the data exchange content to be parsed; if the storage capacity is less than the amount of data in the data exchange content to be parsed, creating a second contiguous memory region for storing binary data; the storage capacity of the second contiguous memory region is greater than the storage capacity of the first contiguous memory region; and storing the data exchange content to be parsed based on the first and second contiguous memory regions.

[0007] In one example, storing the data exchange content to be parsed based on the first contiguous memory region and the second contiguous memory region specifically includes: determining whether a user's storage region instruction has been received; if so, storing the data exchange content to be parsed through the second contiguous memory region according to the user's storage region instruction; if not, storing a portion of the data exchange content to be parsed into the first contiguous memory region; the data volume of the portion is equal to the storage capacity of the first contiguous memory region; and storing the remaining content other than the portion in the data exchange content to be parsed into the second contiguous memory region.

[0008] In one example, determining the view type of the typed array of the data exchange content to be parsed based on the data volume of the data exchange content to be parsed specifically includes: retrieving the target data volume range into which the data volume of the data exchange content to be parsed falls in a pre-built view type mapping table; determining the view type corresponding to the target data volume range; and determining the corresponding view type as the view type of the typed array of the data exchange content to be parsed; the larger the data volume, the higher the number of bits in the view type.

[0009] In one example, before establishing a WebSocket protocol connection with the web application client, the method further includes: establishing an HTTP protocol connection with the web application client; receiving an HTTP request sent by the web application client, parsing the HTTP request to obtain a first header parameter; the first header parameter includes Connection, Upgrade, and Sec-WebSocket-Key; converting the first header parameter to obtain a second header parameter; wherein the second header parameter includes Connection, Upgrade, and Sec-WebSocket-Accept; the Sec-WebSocket-Accept is obtained based on the Sec-WebSocket-Key; and generating a header to be returned to the web application client based on the second header parameter, so as to establish a WebSocket protocol connection with the web application client.

[0010] In one example, the Sec-WebSocket-Accept is obtained based on the Sec-WebSocket-Key, specifically including: determining a pre-set fixed string; concatenating the fixed string with the Sec-WebSocket-Key to obtain a concatenated string; the fixed string being appended to the Sec-WebSocket-Key; encrypting the concatenated string to obtain an encrypted result; and base64 encoding the encrypted result to obtain the Sec-WebSocket-Accept.

[0011] In one example, before receiving the data exchange request from the web application client, the method further includes: the web application client determining the protocol format of the data exchange request; wherein, in the protocol format, the last four bits of the first byte are extracted as the opcode; the first bit of the second byte is extracted as the mask flag; the payload length is determined according to the data length of the data exchange content; the fourth byte is extracted as the mask key; the data exchange content is used as payload data; the user's input data is encoded according to the protocol format to generate the data exchange request; and the send method is called to convert the data exchange request into buffer data so as to send the data exchange request to the web server.

[0012] In one example, after accessing the signed integer array and parsing the binary exchange data of the data exchange content to be parsed, the method further includes: determining the feedback exchange data to be returned to the web application client; setting the highest bit of the first byte of the feedback exchange data to 1, and adding an opcode after the highest bit; using the length of the feedback exchange data as the second byte, and concatenating the feedback exchange data after the second byte to generate the encoded data of the feedback exchange data.

[0013] On the other hand, embodiments of this application provide a data exchange device for a web application, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to: establish a WebSocket protocol connection with a web application client; receive a data exchange request from the web application client, parse the data exchange request to obtain data exchange content to be parsed; the data exchange content to be parsed is encoded binary data; store the data exchange content to be parsed according to a pre-created contiguous memory region for storing binary data; determine a view type of a typed array of the data exchange content to be parsed according to the data volume of the data exchange content to be parsed, format the data exchange content to be parsed in the contiguous memory region using the view type to obtain a signed integer array; access the signed integer array and parse it to obtain the binary exchange data of the data exchange content to be parsed.

[0014] On the other hand, embodiments of this application provide a non-volatile computer storage medium for data exchange in web applications, storing computer-executable instructions configured to: establish a WebSocket protocol connection with a web application client; receive a data exchange request from the web application client, parse the data exchange request to obtain data exchange content to be parsed; the data exchange content to be parsed is encoded binary data; store the data exchange content to be parsed according to a pre-created contiguous memory region for storing binary data; determine a view type of a typed array of the data exchange content to be parsed according to the data volume of the data exchange content to be parsed, format the data exchange content to be parsed in the contiguous memory region using the view type to obtain a signed integer array; access the signed integer array and parse it to obtain the binary exchange data of the data exchange content to be parsed.

[0015] The above-described technical solutions adopted in the embodiments of this application can achieve the following beneficial effects:

[0016] The WebSocket protocol supports real-time data exchange, improving the response speed of web applications. It enables binary transmission over WebSocket connections, offering large transmission capacity. A pre-created contiguous memory area for storing binary data allows for more efficient storage of the exchanged data. Furthermore, based on the amount of data to be parsed, the view type of the typed array of the exchanged data is determined. Taking into account data volume, it automatically selects the most efficient view type, thus parsing the binary exchanged data more efficiently. Ultimately, this improves the data exchange efficiency of web applications and provides users with a better business experience. Attached Figure Description

[0017] To more clearly illustrate the technical solution of this application, some embodiments of this application will be described in detail below with reference to the accompanying drawings, in which:

[0018] Figure 1 A flowchart illustrating a data exchange method for a web application provided in an embodiment of this application;

[0019] Figure 2 A schematic diagram illustrating a protocol conversion process provided in an embodiment of this application;

[0020] Figure 3 A schematic diagram illustrating a protocol format for a data exchange request provided in an embodiment of this application;

[0021] Figure 4 This application provides a schematic diagram illustrating the correspondence between view type and byte count in an embodiment.

[0022] Figure 5 This is a schematic diagram illustrating an application scenario where view type parsing is used to parse the content of data exchange.

[0023] Figure 6 This is a schematic diagram of the structure of a data exchange device for a web application, provided as an embodiment of this application. Detailed Implementation

[0024] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0025] Some embodiments of this application will now be described in detail with reference to the accompanying drawings.

[0026] Figure 1 This is a flowchart illustrating a data exchange method for web applications, provided as an embodiment of this application. This method can be applied to various business domains, such as internet finance, e-commerce, instant messaging, gaming, and government services. Certain input parameters or intermediate results in this process can be manually adjusted to help improve accuracy.

[0027] The analysis method involved in the embodiments of this application is implemented by a server, and the following embodiments are all described in detail using a server as an example.

[0028] It should be noted that the server can be a single device or a system composed of multiple devices, i.e., a distributed server. This application does not make any specific limitations on this.

[0029] Figure 1 The process may include the following steps:

[0030] S101: Establish a WebSocket protocol connection with the web application client.

[0031] Among them, the Node.js runtime environment is used: The Node.js runtime environment has high-speed and smooth execution capabilities, which can improve the performance of web applications.

[0032] In some embodiments of this application, it is first necessary to switch the HTTP protocol to the WebSocket protocol.

[0033] Specifically, first, an HTTP protocol is established between the client and the web application. Then, the HTTP request sent by the web application client is received, the HPPT request is parsed, and the first header parameter of the HPPT request is obtained.

[0034] The first header parameter includes Connection, Upgrade, and Sec-WebSocket-Key.

[0035] Then, the first header parameter is converted to obtain the second header parameter; the second header parameter includes Connection, Upgrade, and Sec-WebSocket-Accept.

[0036] Finally, based on the second header parameter, a header is generated and returned to the web application client to establish the WebSocket protocol with the web application client.

[0037] It should be noted that Sec-WebSocket-Accept is obtained based on Sec-WebSocket-Key.

[0038] Specifically, first, a pre-defined fixed string is determined. For example, the fixed string is 258EAFA5-E914-47DA-95CA-C5AB0DC85B11. Then, the fixed string is concatenated with Sec-WebSocket-Key to obtain the concatenated string. The fixed string follows Sec-WebSocket-Key. Next, the concatenated string is encrypted to obtain the encrypted result. Finally, the encrypted result is base64 encoded to obtain Sec-WebSocket-Accept.

[0039] In other words, the parameter values ​​for Connection and Upgrade are the same between the first header parameter and the second header parameter.

[0040] More intuitively, Figure 2 This is a schematic diagram of a protocol conversion process provided in an embodiment of this application.

[0041] exist Figure 2 In the process of switching from the HTTP protocol to the WebSocket protocol, in addition to the upgrade header, the sec-websocket-key is also required. The server calculates the result based on this key. This calculation process is relatively fixed, which is the result of encrypting the key + a fixed string through SHA1 and then base64.

[0042] The response returned via sec-websocket-accept. The response was a 101 Switching Protocols status code.

[0043] Therefore, since the HTTP protocol is based on a request-response model, each request needs to carry a lot of header information, including cookies, user-agent, etc. This header information will consume a lot of bandwidth, while the above method can save bandwidth.

[0044] S102: Receive the data exchange request from the web application client, parse the data exchange request, and obtain the data exchange content to be parsed; the data exchange content to be parsed is encoded binary data.

[0045] In some embodiments of this application, the web application client needs to generate a data exchange request in advance.

[0046] Specifically, the web application client determines the protocol format of the data exchange request. Within this protocol format, the last four bits of the first byte are extracted as the opcode. Then, the first bit of the second byte is extracted as the mask flag. Next, the payload length is determined based on the length of the data exchanged. Then, the fourth byte is extracted as the mask key. Finally, the data exchanged is used as the payload data.

[0047] More intuitively, Figure 3 This is a schematic diagram of a protocol format for a data exchange request provided in an embodiment of this application.

[0048] exist Figure 3 In the first byte, the last four bits are the opcode. The first bit of the second byte is the mask flag. The last seven bits are the payload length. Because the data exchange content is not of fixed length, the WebSocket protocol stipulates that if the last seven bits do not exceed 125, then it is the payload length. If the content is 126, the last 16 bits are used as the payload length. If the content is 127, the last 64 bits are used as the payload length. The fourth byte is the mask key.

[0049] It should be noted that the mask key is used to decrypt and obtain the data exchange content to be parsed. This can be achieved by performing a bitwise XOR operation between the mask key of each byte and each bit of the data.

[0050] Then, the user's input data is encoded according to the protocol format to generate a data exchange request; finally, the send method is called to convert the data exchange request into buffer data and send it to the web server.

[0051] S103: Store the data exchange content to be parsed according to the pre-created contiguous memory area for storing binary data.

[0052] In some embodiments of this application, sending binary data using JavaScript requires storing the binary data. Therefore, a contiguous memory region is created by default. However, since the storage capacity of the contiguous memory region is less than the amount of data in the data exchange content to be parsed, storage is not possible. Therefore, it is necessary to compare the storage capacity with the amount of data in the data exchange content to be parsed.

[0053] Specifically, first, the first contiguous memory region for storing binary data, and the storage capacity of the first contiguous memory region, are determined.

[0054] For example, to generate an 8-byte memory region, the value of each byte is 0 by default. 1 byte (Byte) is 8 bits (bit). 1 bit is a binary digit (0 or 1). There are a total of 8*8=64 bits. Each binary digit is 0. Each byte is composed of eight 0s: 0000 0000.

[0055] Then, the storage capacity is compared with the amount of data in the data exchange content to be parsed.

[0056] If the storage capacity is less than the amount of data to be parsed and exchanged, a second contiguous memory region is created to store the binary data. The storage capacity of the second contiguous memory region is greater than that of the first contiguous memory region.

[0057] Finally, the data to be parsed and exchanged is stored based on the first contiguous memory region and the second contiguous memory region.

[0058] It should be noted that if the storage capacity is greater than or equal to the amount of data to be parsed and exchanged, a second contiguous memory area for storing binary data will not be created.

[0059] The data to be parsed is stored based on the first and second contiguous memory regions. The first contiguous memory region can be filled completely, or, based on user instructions, the entire data to be parsed can be stored in the second contiguous memory region. It should be noted that the storage capacity of the second contiguous memory region must be greater than or equal to the amount of data to be parsed.

[0060] Based on this, it is determined whether a user's storage area instruction has been received.

[0061] If so, the data to be parsed is stored in the second contiguous memory region according to the user's storage area instructions.

[0062] If not, a portion of the data to be parsed and exchanged will be stored in the first contiguous memory region. The amount of data in this portion will equal the storage capacity of the first contiguous memory region. In other words, the first contiguous memory region will be pre-filled.

[0063] In the data exchange content to be parsed, the remaining content, except for a portion of the content, is stored in the second contiguous memory area.

[0064] S104: Based on the amount of data in the data exchange content to be parsed, determine the view type of the typed array of the data exchange content to be parsed, and format the data exchange content to be parsed in the contiguous memory region through the view type to obtain a signed integer array.

[0065] In some embodiments of this application, the larger the amount of data, the higher the number of bits in the view type if there is only one view, thus improving processing efficiency.

[0066] Based on this, in the pre-built view type mapping table, the target data volume range into which the data volume of the data exchange content to be parsed falls is retrieved.

[0067] Then, determine the view type corresponding to the target data volume range, and set the corresponding view type as the view type of the typed array of the data exchange content to be parsed.

[0068] It should be noted that multiple smaller view types can also be used. If the capacity of the first view type is insufficient, the excess portion can be handled by a second view type.

[0069] More intuitively, Figure 4 This is a schematic diagram illustrating the correspondence between view type and byte count, provided as an embodiment of this application.

[0070] based on Figure 4 The content varies depending on the view type, with different numbers of bytes required.

[0071] S105: Access the signed integer array and parse it to obtain the binary exchange data of the data exchange content to be parsed.

[0072] More intuitively, Figure 5 This is a schematic diagram illustrating the parsing of data exchange content through view type parsing in an application scenario provided by an embodiment of this application.

[0073] exist Figure 5 In binary data exchange, when the exchanged data is 16 bytes, the data to be parsed can be formatted into a 32-bit (4-byte) signed integer array using the Int32Array view type. Elements in this array can be accessed in the same way as ordinary arrays; this view is [0, 2, 4, 6]. Alternatively, another Int16Array view can be created to format the exchanged data into a 16-bit (2-byte) signed integer array; accessing this array will yield [0, 0, 2, 0, 4, 0, 6, 0].

[0074] It should be noted that during the parsing of buffer data, byte truncation processing is required according to the protocol format.

[0075] It should be noted that in the buffer data shown in the figure, the x86 system uses little-endian bytes to store data, so the three numbers 2, 4, and 6 are placed before 0. The memory size in the figure above is arranged from left to right, and int32View[1] corresponds to 4 bytes. The value it fills in is 10 (the binary representation of 2). If 0 is padded, it will be 00000000 000000000000000 00000010. The computer will fill it in reverse, and it will eventually become 00000010 00000000 000000000000000000. The little-endian byte corresponds to the big-endian byte order, which is the order in which users usually read numbers.

[0076] It should be noted that, although the embodiments in this application are based on... Figure 1 Steps S101 to S105 will be described sequentially, but this does not mean that steps S101 to S105 must be performed in a strict order. The reason this embodiment follows this order is... Figure 1 The order in which steps S101 to S105 are described is provided to facilitate understanding of the technical solutions of the embodiments of this application by those skilled in the art. In other words, in the embodiments of this application, the order of steps S101 to S105 can be appropriately adjusted according to actual needs.

[0077] pass Figure 1 The WebSocket protocol supports real-time data exchange, improving the response speed of web applications. It enables binary transmission over WebSocket connections, offering large transmission capacity. A pre-created contiguous memory area for storing binary data allows for more efficient storage of the data to be parsed. Furthermore, based on the amount of data to be parsed, the view type of the typed array of the data to be parsed is determined. Considering the data volume, the view type can be automatically selected for more efficient processing, thus parsing the binary data more efficiently. Ultimately, this improves the data exchange efficiency of web applications and provides users with a better business experience.

[0078] Based on the same idea, some embodiments of this application also provide devices and non-volatile computer storage media corresponding to the above methods.

[0079] Figure 6 A schematic diagram of a data exchange device for web applications provided in this application embodiment includes:

[0080] At least one processor; and,

[0081] A memory communicatively connected to the at least one processor; wherein,

[0082] The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enable the at least one processor to:

[0083] Establish a WebSocket protocol connection with the web application client;

[0084] The system receives a data exchange request from the web application client, parses the data exchange request, and obtains the data exchange content to be parsed; the data exchange content to be parsed is encoded binary data.

[0085] The data exchange content to be parsed is stored in a pre-created contiguous memory region for storing binary data;

[0086] Based on the amount of data in the data exchange content to be parsed, determine the view type of the typed array of the data exchange content to be parsed, and format the data exchange content to be parsed in the contiguous memory region through the view type to obtain a signed integer array;

[0087] The signed integer array is accessed and parsed to obtain the binary exchange data of the data to be parsed.

[0088] Some embodiments of this application provide a non-volatile computer storage medium for data exchange in web applications, storing computer-executable instructions configured as follows:

[0089] Establish a WebSocket protocol connection with the web application client;

[0090] The system receives a data exchange request from the web application client, parses the data exchange request, and obtains the data exchange content to be parsed; the data exchange content to be parsed is encoded binary data.

[0091] The data exchange content to be parsed is stored in a pre-created contiguous memory region for storing binary data;

[0092] Based on the amount of data in the data exchange content to be parsed, determine the view type of the typed array of the data exchange content to be parsed, and format the data exchange content to be parsed in the contiguous memory region through the view type to obtain a signed integer array;

[0093] The signed integer array is accessed and parsed to obtain the binary exchange data of the data to be parsed.

[0094] The various embodiments in this application are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device and medium embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the description of the method embodiments.

[0095] The devices and media provided in this application are one-to-one with the methods. Therefore, the devices and media also have similar beneficial technical effects as their corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the devices and media will not be repeated here.

[0096] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0097] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0098] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0099] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0100] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0101] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0102] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0103] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0104] The above description is merely an embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the technical principles of this application should fall within the protection scope of this application.

Claims

1. A data exchange method for web applications, characterized in that, The method includes: Establish a WebSocket protocol connection with the web application client; The system receives a data exchange request from the web application client, parses the data exchange request, and obtains the data exchange content to be parsed; the data exchange content to be parsed is encoded binary data. The data exchange content to be parsed is stored in a pre-created contiguous memory region for storing binary data; Based on the amount of data in the data exchange content to be parsed, determine the view type of the typed array of the data exchange content to be parsed, and format the data exchange content to be parsed in the contiguous memory region through the view type to obtain a signed integer array; The signed integer array is accessed and parsed to obtain the binary exchange data of the data to be parsed; The step of storing the data to be parsed in a pre-created contiguous memory region for storing binary data specifically includes: Determine the first contiguous memory region that is pre-created to store binary data, and the storage capacity of the first contiguous memory region; Compare the storage capacity with the amount of data in the data exchange content to be parsed; If the storage capacity is less than the amount of data in the data exchange content to be parsed, a second contiguous memory region for storing binary data is created; the storage capacity of the second contiguous memory region is greater than the storage capacity of the first contiguous memory region. The data exchange content to be parsed is stored based on the first contiguous memory region and the second contiguous memory region; The step of storing the data exchange content to be parsed based on the first contiguous memory region and the second contiguous memory region specifically includes: Determine whether a user's storage area instruction has been received; If so, the data exchange content to be parsed is stored in the second contiguous memory region according to the user's storage region instruction; If not, then a portion of the data exchanged to be parsed is stored in the first contiguous memory region; the amount of data in the portion is equal to the storage capacity of the first contiguous memory region. In the data exchange content to be parsed, the remaining content other than the aforementioned portion is stored in the second contiguous memory region; The step of determining the view type of the typed array of the data to be parsed based on the data volume of the data exchange content specifically includes: In a pre-built view type mapping table, retrieve the target data volume range into which the data volume of the data exchange content to be parsed falls; Determine the view type corresponding to the target data volume range, and set the corresponding view type as the view type of the typed array of the data exchange content to be parsed; the larger the data volume, the higher the number of bits in the view type.

2. The method according to claim 1, characterized in that, Before establishing a WebSocket protocol connection with the web application client, the method further includes: Establish the HTTP protocol between the web application client and the client. The system receives an HTTP request sent by the web application client, parses the HTTP request, and obtains a first header parameter; the first header parameter includes Connection, Upgrade, and Sec-WebSocket-Key. The first header parameter is transformed to obtain the second header parameter; wherein the second header parameter includes Connection, Upgrade, and Sec-WebSocket-Accept; the Sec-WebSocket-Accept is obtained based on the Sec-WebSocket-Key; Based on the second header parameter, a header is generated and returned to the web application client to establish a websocket protocol with the web application client.

3. The method according to claim 2, characterized in that, The Sec-WebSocket-Accept is obtained based on the Sec-WebSocket-Key, specifically including: Define a pre-set fixed string; The fixed string is concatenated with the Sec-WebSocket-Key to obtain the concatenated string; the fixed string follows the Sec-WebSocket-Key. The concatenated string is encrypted to obtain the encrypted result; The encryption result is base64 encoded to obtain the Sec-WebSocket-Accept.

4. The method according to claim 1, characterized in that, Before receiving the data exchange request from the web application client, the method further includes: The web application client determines the protocol format of the data exchange request; wherein, in the protocol format, the last four bits of the first byte are extracted as the opcode; the first bit of the second byte is extracted as the mask flag; the payload length is determined according to the data length of the data exchange content; the fourth byte is extracted as the mask key; and the data exchange content is used as the payload data. The user's input data is encoded according to the protocol format to generate the data exchange request; The send method is called to convert the data exchange request into buffer data and send the data exchange request to the web server.

5. The method according to claim 1, characterized in that, After accessing the signed integer array and parsing to obtain the binary exchange data of the data to be parsed, the method further includes: Determine the feedback exchange data to be returned to the web application client; Set the most significant bit of the first byte of the feedback exchange data to 1, and add the opcode after the most significant bit; The length of the feedback exchange data is used as the second byte, and the feedback exchange data is concatenated after the second byte to generate the encoded data of the feedback exchange data.

6. A data exchange device for web applications, characterized in that, include: At least one processor; as well as, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to: perform a data exchange method for a web application as described in any one of claims 1-5.

Citation Information

Patent Citations

  • Data exchange file analysis method and device

    CN110008266A

  • Duplex full-duplex communication method and device, computer equipment and storage medium

    CN112689014A

  • Memory management method, system and device and readable storage medium

    CN113010453A