Data processing method and device and computer readable storage medium

By establishing a port connection between the sharedWorker port and the page port and listening to connect messages, the sharing of websocket connections is solved, and the problem of websocket connection sharing in multiple page scenarios is reduced, server resource occupancy rate and performance is improved.

CN119603343APending Publication Date: 2025-03-11CHINA MERCHANTS BANK
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411695939.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-25
Publication Date
2025-03-11

AI Technical Summary

Technical Problem

In multi-page scenarios, how to realize the sharing of websocket connections to reduce excessive consumption of server resources and improve server performance.

Method used

By establishing a port connection between the sharedWorker port and the page port, listening to the connect message of the page port, and performing message distribution operations based on the existing websocket connection, realizing the sharing of websocket connection.

Benefits of technology

Implement websocket connection sharing in multi-page scenarios, reduce server resource occupancy and improve server performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119603343A_ABST
    Figure CN119603343A_ABST
Patent Text Reader

Abstract

The invention discloses a data processing method and device and a computer readable storage medium, and the method comprises the following steps: when a port connection is established between a shadWorker port and a first page port, executing a monitoring operation through the shadWorker port; if the connect message sent by the first page port is monitored, determining whether a websocket connection corresponding to the sharedWorker port exists at present or not, and if the connect message sent by the first page port is monitored, determining whether the websocket connection corresponding to the sharedWorker port exists or not; and if the websocket connection corresponding to the sharedWorker port exists at present, executing a distribution operation of a message corresponding to the first page port on the basis of the websocket connection. According to the method and the device, the connect message of the page port is monitored through the sharedWorker port, and the message distribution of the page port is executed through the existing websocket connection, so that the sharing of the websocket connection is realized in a multi-page scene, the resource occupancy rate of the server is reduced, and the performance of the server is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a data processing method, device and computer-readable storage medium. Background Art

[0002] Real-time message push is an indispensable system function in the network, which greatly improves the user interaction experience and the efficiency of information transmission. In traditional web applications, the client usually needs to read the interface in a regular loop to obtain the latest news. With the development of technologies such as websocket, a long connection can be established between the client page and the backend server to allow the server to actively push messages to the client. Since websocket is a persistent connection, the server needs to maintain the connection status all the time, which will occupy memory and CPU resources. If the server needs to maintain a large number of connections in a high-concurrency scenario, it will cause excessive consumption of server resources.

[0003] Currently, websocket connections are usually used in single-page application architecture scenarios to reduce the creation and destruction of WebSockets caused by page switching, thereby reducing server pressure. However, cross-domain application systems are usually composed of multiple single-page applications with multiple domain names, and the pages have complex nested logic. In order to achieve global message notifications, a large number of websocket connections need to be established, which places extremely high requirements on server performance.

[0004] Therefore, how to share websocket connections in a multi-page scenario is a problem that needs to be solved urgently. Summary of the invention

[0005] The main purpose of this application is to provide a data processing method, device and computer-readable storage medium, aiming to solve the technical problem of how to share websocket connections in a multi-page scenario.

[0006] To achieve the above object, the present application provides a data processing method, which comprises the following steps:

[0007] When a port connection is established between the sharedWorker port and the first page port, a monitoring operation is performed through the sharedWorker port;

[0008] If a connect message sent by the first page port is monitored, determine whether there is a websocket connection corresponding to the sharedWorker port;

[0009] If there is currently a websocket connection corresponding to the sharedWorker port, a distribution operation of the message corresponding to the first page port is performed based on the websocket connection.

[0010] Furthermore, if there is currently a websocket connection corresponding to the sharedWorker port, the step of performing a distribution operation of a message corresponding to the first page port based on the websocket connection includes:

[0011] If there is currently a websocket connection corresponding to the sharedWorker port, a registration operation is performed based on the first page port;

[0012] Adding the first page port to the websocket message receiving queue corresponding to the websocket connection;

[0013] Based on the websocket message receiving queue, a distribution operation of the message corresponding to the first page port is performed through a websocket connection.

[0014] Furthermore, after the step of adding the first page port to the websocket message receiving queue corresponding to the websocket connection, the data processing method further includes:

[0015] If a close message is monitored, the first page port corresponding to the close message is removed from the websocket message receiving queue;

[0016] The port connection between the sharedWorker port and the first page port is disconnected.

[0017] Furthermore, if the connect message sent by the first page port is monitored, the step of determining whether there is currently a websocket connection corresponding to the sharedWorker port includes:

[0018] If a connect message sent by the first page port is monitored, the source information corresponding to the connect message is obtained, and the source information is verified;

[0019] When the source information is verified, it is determined whether there is a websocket connection corresponding to the sharedWorker port.

[0020] Furthermore, after the step of determining whether there is a websocket connection corresponding to the sharedWorker port if the connect message sent by the first page port is monitored, the data processing method further includes:

[0021] If there is no websocket connection corresponding to the sharedWorker port currently, establish a websocket connection based on the sharedWorker port;

[0022] Perform a registration operation based on the first page port, and add the first page port to the websocket message receiving queue corresponding to the websocket connection;

[0023] Based on the websocket message receiving queue, a distribution operation of the message corresponding to the first page port is performed through a websocket connection.

[0024] Furthermore, when establishing a connection between the sharedWorker port and the page port, before the step of performing a monitoring operation through the sharedWorker port, the data processing method further includes:

[0025] Establish a homologous base for providing blank pages based on an exclusive domain name;

[0026] Mounting a blank page of the homologous base based on the iframe element of the page corresponding to the page port, and starting the monitoring function corresponding to the blank page;

[0027] If the initialization information of the page corresponding to the page port is monitored through the blank page, a port connection between the sharedWorker port and the port corresponding to the blank page, and a port connection between the port corresponding to the blank page and the page port are established.

[0028] Furthermore, if the initialization information corresponding to the blank page is monitored, after the step of establishing a port connection between the sharedWorker port and the page port, the data processing method further includes:

[0029] When receiving the information to be sent from the backend service, obtaining the message source corresponding to the information to be sent;

[0030] In the websocket message receiving queue, the target page port corresponding to the message source is determined, and the information to be sent is sent to the target page port.

[0031] Furthermore, if the initialization information corresponding to the blank page is monitored, after the step of establishing a port connection between the sharedWorker port and the page port, the data processing method further includes:

[0032] When new source information sent by the second page port is received through the homologous base, the port connection between the sharedWorker port and all page ports in the websocket message receiving queue is disconnected;

[0033] Remove all page ports from the websocket message receiving queue and return to execute the step of establishing a port connection between the sharedWorker port and the page port.

[0034] In addition, to achieve the above-mentioned purpose, the present application also provides a data processing device, which includes: a memory, a processor, and a data processing program stored in the memory and executable on the processor, and the data processing program implements the steps of the aforementioned data processing method when executed by the processor.

[0035] In addition, to achieve the above-mentioned purpose, the present application also provides a computer-readable storage medium, on which a data processing program is stored, and when the data processing program is executed by a processor, the steps of the aforementioned data processing method are implemented.

[0036] The present application performs a monitoring operation through the sharedWorker port when establishing a port connection between the sharedWorker port and the page port; then, if a connect message sent by the page port is monitored, it is determined whether there is currently a websocket connection corresponding to the sharedWorker port; and then, if there is currently a websocket connection corresponding to the sharedWorker port, a distribution operation of the message corresponding to the page port is performed based on the websocket connection, the connect message of the page port is monitored through the sharedWorker port, and the message distribution of the page port is performed through the existing websocket connection, so as to realize the sharing of websocket connections in multi-page scenarios, reduce the resource utilization rate of the server, and improve the performance of the server. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0038] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0039] Figure 1 A flowchart of the first embodiment of the data processing method of the present application is provided;

[0040] Figure 2 This is a schematic diagram of the module structure of the data processing device according to an embodiment of the present application.

[0041] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0042] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0043] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0044] The main solution of the present application is: when a port connection is established between the sharedWorker port and the first page port, a listening operation is performed through the sharedWorker port; if a connect message sent by the first page port is listened to, it is determined whether there is a websocket connection corresponding to the sharedWorker port; if there is a websocket connection corresponding to the sharedWorker port, a distribution operation of the message corresponding to the first page port is performed based on the websocket connection.

[0045] At present, real-time message push is an indispensable system function in the network, which greatly improves the user interaction experience and the efficiency of information transmission. In traditional web applications, the client usually needs to read the interface in a regular loop to obtain the latest news. With the development of technologies such as websocket, a long connection can be established between the client page and the backend server to allow the server to actively push messages to the client. Since websocket is a persistent connection, the server needs to maintain the connection status all the time, which will occupy memory and CPU resources. If the server needs to maintain a large number of connections in a high-concurrency scenario, it will cause excessive consumption of server resources.

[0046] Currently, websocket connections are usually used in single-page application architecture scenarios to reduce the creation and destruction of WebSockets caused by page switching, thereby reducing server pressure. However, cross-domain application systems are usually composed of multiple single-page applications with multiple domain names, and the pages have complex nested logic. In order to achieve global message notifications, a large number of websocket connections need to be established, which places extremely high demands on server performance. Therefore, how to share websocket connections in multi-page scenarios is a problem that needs to be solved urgently.

[0047] This application listens to the connect message of the page port through the sharedWorker port, and distributes the message of the execution port through the existing websocket connection, so as to realize the sharing of websocket connection in multi-page scenarios, reduce the resource utilization of the server, and improve the performance of the server.

[0048] It should be noted that the execution subject of this embodiment may be a data processing device, or a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or a data processing device capable of realizing the above functions, etc., and this embodiment does not specifically limit this. The following takes the data processing device as the execution subject as an example to illustrate this embodiment and the following embodiments.

[0049] Based on this, this application proposes a data processing method of the first embodiment, please refer to Figure 1 , the data processing method comprises steps S101 to S103:

[0050] Step S101, when a port connection is established between a sharedWorker port and a first page port, a monitoring operation is performed through the sharedWorker port;

[0051] In this embodiment, the data processing method involves a channel connection project and a shared communication project. The channel connection project works on the sharedWorker background thread to mount the channel connection project through the sharedworker thread. The channel connection project is used to establish a websocket connection with the backend, and the shared communication project is used to establish a connection between the front-end page port and the sharedWorker.

[0052] In this embodiment, when a port connection is established between the sharedWorker port and the first page port, monitoring of the sharedWorker port is started to perform a monitoring operation through the sharedWorker port to monitor messages sent by the first page port, wherein messages sent by multiple page ports can be monitored through the sharedWorker port.

[0053] Step S102, if a connect message sent by the first page port is monitored, determine whether there is a websocket connection corresponding to the sharedWorker port;

[0054] In this embodiment, if the connect message sent by the first page port is monitored through the sharedWorker port, and the onconnect method is implemented through the connect message, it is determined whether there is a websocket connection corresponding to the sharedWorker port. By judging whether a websocket connection already exists, a connection is established between the first page port and the existing websocket connection to realize the sharing of the websocket connection.

[0055] Further, in a feasible implementation manner, step S101 may include steps S1021 to S1022:

[0056] Step S1021, if a connect message sent by the first page port is monitored, then the source information corresponding to the connect message is obtained, and the source information is verified;

[0057] Step S1022, when the source information verification passes, determine whether there is currently a websocket connection corresponding to the sharedWorker port.

[0058] In this embodiment, if the connect message sent by the first page port is monitored through the sharedWorker port, the source information corresponding to the connect message is obtained. The source information is the information of the source party corresponding to the connect message. When the source information is obtained, the source information is verified to verify the source party corresponding to the source information, for example, to verify the authority of the source party.

[0059] If the source information verification passes, it is determined whether there is a websocket connection corresponding to the sharedWorker port. By judging whether a websocket connection already exists, a connection is established between the first page port and the existing websocket connection to realize the sharing of the websocket connection.

[0060] Step S103: If there is currently a websocket connection corresponding to the sharedWorker port, a distribution operation of the message corresponding to the first page port is performed based on the websocket connection.

[0061] In this embodiment, if there is currently a websocket connection corresponding to the sharedWorker port, the distribution operation of the message corresponding to the first page port is performed based on the websocket connection, that is, an association relationship between the first page port and the websocket connection is established to perform the distribution operation of the message corresponding to the first page port through the websocket connection. Further, in a feasible implementation manner, step S103 may include steps S1031 to S1033:

[0062] Step S1031: If there is currently a websocket connection corresponding to the sharedWorker port, a registration operation is performed based on the first page port;

[0063] Step S1032, adding the first page port to the websocket message receiving queue corresponding to the websocket connection;

[0064] Step S1033: Distributing the message corresponding to the first page port through the websocket connection based on the websocket message receiving queue.

[0065] In this embodiment, if there is currently a websocket connection corresponding to the sharedWorker port, a registration operation is performed based on the first page port. Specifically, the registration operation of the source party can be performed based on the source information, and the source information can be the user's username, etc.

[0066] In this embodiment, when a websocket connection is established, a websocket message receiving queue corresponding to the websocket connection is generated, and after the source party registers, the first page port is added to the websocket message receiving queue corresponding to the websocket connection, so that the websocket connection can be called through the websocket message receiving queue to execute the distribution operation of the message corresponding to the first page port.

[0067] Furthermore, in a feasible implementation manner, after step S103, the data processing method may further include steps S104 to S106:

[0068] Step S104, if there is no websocket connection corresponding to the sharedWorker port currently, establish a websocket connection based on the sharedWorker port;

[0069] Step S105, performing a registration operation based on the first page port, and adding the first page port to a websocket message receiving queue corresponding to the websocket connection;

[0070] Step S106: Execute a distribution operation of the message corresponding to the first page port through a websocket connection based on the websocket message receiving queue.

[0071] In this embodiment, if there is currently no websocket connection corresponding to the sharedWorker port, the shared communication project is implemented through the sharedWorker port, that is, a websocket connection is established based on the sharedWorker port. Specifically, a new websocket connection is initialized, and a listener corresponding to the websocket connection is established. At the same time, a websocket message receiving queue corresponding to the websocket connection is established to maintain the port information of each page port through the websocket message receiving queue.

[0072] Next, a registration operation is performed based on the first page port, and the first page port is added to the websocket message receiving queue corresponding to the websocket connection; specifically, the source party's registration operation can be performed based on the source information, and the source information can be the user name of the user, etc. Since the websocket message receiving queue corresponding to the websocket connection has been generated when the websocket connection is established, after the source party registers, the first page port is added to the websocket message receiving queue corresponding to the websocket connection, so that the websocket connection is called through the websocket message receiving queue to perform the distribution operation of the message corresponding to the page port.

[0073] Furthermore, in a feasible implementation manner, after step S1032, the data processing method may further include steps a1 to a2:

[0074] Step a1: if a close message is monitored, remove the first page port corresponding to the close message from the websocket message receiving queue;

[0075] Step a2, disconnecting the port connection between the sharedWorker port and the first page port.

[0076] In this embodiment, when the page port is monitored through the sharedWorker port, the close message sent by the first page port will be monitored through the sharedWorker port. The first page port may be the same as or different from the first page port. If the close message sent by the first page port is monitored, the first page port corresponding to the close message is removed from the websocket message receiving queue.

[0077] After the first page port is removed from the websocket message receiving queue, the port connection between the sharedWorker port and the first page port is disconnected to disconnect the page port from the websocket.

[0078] The data processing method proposed in this embodiment performs a monitoring operation through the sharedWorker port when a port connection is established between the sharedWorker port and the page port; then, if a connect message sent by the page port is monitored, it is determined whether there is currently a websocket connection corresponding to the sharedWorker port; and then, if there is currently a websocket connection corresponding to the sharedWorker port, a distribution operation of the message corresponding to the page port is performed based on the websocket connection, the connect message of the page port is monitored through the sharedWorker port, and the message distribution of the page port is performed through the existing websocket connection, so as to realize the sharing of websocket connections in multi-page scenarios, reduce the resource utilization rate of the server, and improve the performance of the server.

[0079] In a feasible implementation manner, before step S101, the data processing method may further include steps S201 to S203:

[0080] Step S201, establishing a service for providing a blank page based on a dedicated domain name to obtain a homologous base;

[0081] Step S202, mounting a blank page of the homologous base based on the iframe element of the page corresponding to the page port, and starting a monitoring function corresponding to the blank page;

[0082] Step S203: if the initialization information of the page corresponding to the page port is monitored through the blank page, a port connection between the sharedWorker port and the port corresponding to the blank page, and a port connection between the port corresponding to the blank page and the page port are established.

[0083] In this embodiment, since sharedWorker can only be shared under the same-origin domain name, the web application will start multiple sharedWorkers under different domain names, that is, there will still be multiple websocket connections in the cross-domain scenario. In order to realize the sharing of websocket connections in the cross-domain scenario, a same-origin base is built, and the shared communication project is introduced by the same-origin base, and each page port introduces the same-origin base. Specifically, a service for providing a blank page is established based on an exclusive domain name, namely, the same-origin base. Specifically, a service providing an exclusive domain name is built, and the exclusive domain name provides a blank page to load and run a Javascript project as the same-origin base.

[0084] Next, based on the iframe element of the page corresponding to the page port, the blank page of the homologous base is mounted, and the listening function corresponding to the blank page is started. Specifically, each page port introduces a blank page of the mounted homologous base project through iframe, that is, the blank page is hidden in the page corresponding to the page port, and the blank page is specified to send initialization information through postMessage, and the listening of the blank page information is started. For example, each page port associated with the websocket connection mounts a blank page of the homologous base project.

[0085] Then, if the initialization information of the page corresponding to the page port is monitored through the blank page, a port connection is established between the sharedWorker port and the port corresponding to the blank page, as well as a port connection between the port corresponding to the blank page and the page port. Specifically, after the homologous base is introduced, monitoring is started, and the initialization information of the page corresponding to the page port, that is, the initialization information of the parent page, can be monitored, and the shared channel project is initialized, and the subsequent process of connecting the websocket connection is executed. A port connection is established between the sharedWorker port and the port corresponding to the blank page, and a port connection is established between the port corresponding to the blank page and the page port. Communication between the page port corresponding to the blank page of the homologous base and communication between the blank page and sharedWorker can be achieved, so that page ports of different sources can share a websocket connection by introducing the homologous base, and websocket connection sharing can be achieved in multi-page cross-domain scenarios, reducing server resource usage and improving server performance.

[0086] In a feasible implementation manner, after step S203, steps S204 to S205 may also be included:

[0087] Step S204, when receiving the information to be sent from the backend service, obtaining the message source corresponding to the information to be sent;

[0088] Step S205, in the websocket message receiving queue, determine the target page port corresponding to the message source, and send the information to be sent to the target page port.

[0089] In this embodiment, when the information to be sent is received from the back-end service, the message source corresponding to the information to be sent is obtained, and then, in the websocket message receiving queue, the target page port corresponding to the message source is determined, and the information to be sent is sent to the target page port. For example, the page registers to the websocket message receiving queue on sharedWorker by sending connect information and specifies the message source. After sharedWorker receives the websocket message, it will send it to the corresponding page according to the message source to achieve directional sending of the message to be sent.

[0090] In a feasible implementation manner, after step S203, steps S206 to S207 may also be included:

[0091] Step S206, when new source information sent by the second page port is received through the homologous base, the port connection between the sharedWorker port and all page ports in the websocket message receiving queue is disconnected;

[0092] Step S207, remove all page ports from the websocket message receiving queue, and return to execute the step of establishing a port connection between the sharedWorker port and the page port.

[0093] In this embodiment, under the same browser, the user can be switched after the system logs in, and the above-mentioned source information includes user information. When the user needs to be switched, the page port sends new source information to the channel connection project through the homologous base. The new source information includes new user information. When the new source information sent by the second page port is received through the homologous base, the port connection between the sharedWorker port and all page ports in the websocket message receiving queue is disconnected. After the user switches, the old page can no longer receive real-time messages from the backend.

[0094] At the same time, all page ports are removed from the websocket message receiving queue to avoid sending messages to the page ports in the websocket message receiving queue again, and the step of establishing a port connection between the sharedWorker port and the page port is returned to re-establish the port connection between the page port and the websocket connection based on the new source information.

[0095] It should be noted that after the homology base is established, the same page can monitor multiple message sources through a homology base, and can also send multiple connection information to the shared channel through the homology base to register to receive different message sources.

[0096] The data processing method proposed in this embodiment establishes a homologous base for providing blank pages based on an exclusive domain name; mounts the blank page of the homologous base based on the iframe element of the page corresponding to the page port, and starts the listening function corresponding to the blank page; if the initialization information of the page corresponding to the page port is listened to through the blank page, a port connection is established between the sharedWorker port and the port corresponding to the blank page, and a port connection is established between the port corresponding to the blank page and the page port, so that page ports from different sources can share a websocket connection by introducing the homologous base, and the sharing of websocket connections can be realized in multi-page cross-domain scenarios, thereby reducing the resource usage of the server and improving the performance of the server.

[0097] The data processing device provided in the embodiment of the present application adopts the data processing method in the above embodiment, which can solve the technical problem of how to realize the sharing of websocket connection in a multi-page scenario. Compared with the prior art, the beneficial effects of the data processing device provided in the embodiment of the present application are the same as the beneficial effects of the data processing method provided in the above embodiment, and the other technical features in the data processing device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0098] The present application provides a data processing device, which includes: 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, and the instructions are executed by the at least one processor so that the at least one processor can execute the data processing method in the above-mentioned embodiment 1.

[0099] Reference below Figure 2 , which shows a schematic diagram of the structure of a data processing device suitable for implementing an embodiment of the present application. The data processing device in the embodiment of the present application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 2The data processing device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0100] like Figure 2 As shown, the data processing device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the data processing device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the data processing device to communicate with other devices wirelessly or by wire to exchange data. Although the data processing device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.

[0101] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0102] The data processing device provided by the present application adopts the data processing method in the above embodiment, which can solve the technical problem of how to realize the sharing of websocket connection in a multi-page scenario. Compared with the prior art, the beneficial effects of the data processing device provided by the present application are the same as the beneficial effects of the data processing method provided by the above embodiment, and the other technical features in the data processing device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0103] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0104] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0105] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the data processing method in the above-mentioned embodiment.

[0106] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0107] The computer-readable storage medium may be included in the data processing device; or may exist independently without being installed in the data processing device.

[0108] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the data processing device, the data processing device: when establishing a port connection between the sharedWorker port and the first page port, performs a monitoring operation through the sharedWorker port; if a connect message sent by the first page port is monitored, determines whether there is currently a websocket connection corresponding to the sharedWorker port; if there is currently a websocket connection corresponding to the sharedWorker port, performs a distribution operation of the message corresponding to the first page port based on the websocket connection.

[0109] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0110] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0111] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0112] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned data processing method, and can solve the technical problem of how to share websocket connections in a multi-page scenario. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the data processing method provided in the above-mentioned embodiment, and will not be repeated here.

[0113] An embodiment of the present application provides a computer program product, including a computer program, which implements the steps of the above-mentioned data processing method when executed by a processor.

[0114] The computer program product provided by this application can solve the technical problem of how to share a websocket connection in a multi-page scenario. Compared with the prior art, the beneficial effects of the computer program product provided by the embodiment of this application are the same as the beneficial effects of the data processing method provided by the above embodiment, which will not be repeated here.

[0115] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A data processing method, characterized in that: The data processing method comprises the following steps: When a port connection is established between the sharedWorker port and the first page port, a monitoring operation is performed through the sharedWorker port; If a connect message sent by the first page port is monitored, determine whether there is a websocket connection corresponding to the sharedWorker port; If there is currently a websocket connection corresponding to the sharedWorker port, a distribution operation of the message corresponding to the first page port is performed based on the websocket connection.

2. The data processing method according to claim 1, characterized in that: If there is currently a websocket connection corresponding to the sharedWorker port, the step of performing a distribution operation of a message corresponding to the first page port based on the websocket connection includes: If there is currently a websocket connection corresponding to the sharedWorker port, a registration operation is performed based on the first page port; Adding the first page port to the websocket message receiving queue corresponding to the websocket connection; Based on the websocket message receiving queue, a distribution operation of the message corresponding to the first page port is performed through a websocket connection.

3. The data processing method according to claim 2, characterized in that: After the step of adding the first page port to the websocket message receiving queue corresponding to the websocket connection, the data processing method further includes: If a close message is monitored, the first page port corresponding to the close message is removed from the websocket message receiving queue; The port connection between the sharedWorker port and the first page port is disconnected.

4. The data processing method according to claim 1, characterized in that: If the connect message sent by the first page port is monitored, the step of determining whether there is a websocket connection corresponding to the sharedWorker port currently includes: If a connect message sent by the first page port is monitored, the source information corresponding to the connect message is obtained, and the source information is verified; When the source information is verified, it is determined whether there is a websocket connection corresponding to the sharedWorker port.

5. The data processing method according to claim 1, characterized in that: After the step of determining whether there is a websocket connection corresponding to the sharedWorker port if the connect message sent by the first page port is monitored, the data processing method further includes: If there is no websocket connection corresponding to the sharedWorker port currently, establish a websocket connection based on the sharedWorker port; Perform a registration operation based on the first page port, and add the first page port to the websocket message receiving queue corresponding to the websocket connection; Based on the websocket message receiving queue, a distribution operation of the message corresponding to the first page port is performed through a websocket connection.

6. The data processing method according to any one of claims 1 to 5, characterized in that: When establishing a connection between the sharedWorker port and the page port, before the step of performing a monitoring operation through the sharedWorker port, the data processing method further includes: Establish a homologous base for providing blank pages based on an exclusive domain name; Mounting a blank page of the homologous base based on the iframe element of the page corresponding to the page port, and starting the monitoring function corresponding to the blank page; If the initialization information of the page corresponding to the page port is monitored through the blank page, a port connection between the sharedWorker port and the port corresponding to the blank page, and a port connection between the port corresponding to the blank page and the page port are established.

7. The data processing method according to claim 6, characterized in that: If the initialization information corresponding to the blank page is monitored, after the step of establishing a port connection between the sharedWorker port and the page port, the data processing method further includes: When receiving the information to be sent from the backend service, obtaining the message source corresponding to the information to be sent; In the websocket message receiving queue, the target page port corresponding to the message source is determined, and the information to be sent is sent to the target page port.

8. The data processing method according to claim 6, characterized in that: If the initialization information corresponding to the blank page is monitored, after the step of establishing a port connection between the sharedWorker port and the page port, the data processing method further includes: When new source information sent by the second page port is received through the homologous base, the port connection between the sharedWorker port and all page ports in the websocket message receiving queue is disconnected; Remove all page ports from the websocket message receiving queue and return to execute the step of establishing a port connection between the sharedWorker port and the page port.

9. A data processing device, characterized in that: The data processing device comprises: a memory, a processor, and a data processing program stored in the memory and executable on the processor, wherein the data processing program implements the steps of the data processing method according to any one of claims 1 to 8 when executed by the processor.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a data processing program, and when the data processing program is executed by a processor, the steps of the data processing method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Label page communication method and device, server and storage medium

    CN116069522A

  • Cloud-based web workers and storages

    US20110282940A1