WebSocket-based traffic distributor and method of optimizing websocket connections
Patent Information
- Application Number
- CN202310587614.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-23
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2043-05-23
AI Technical Summary
[0004]然而,现有技术的服务端通过WebSocket与客户端通信时,通常需要开发人员单独开发与每个从应用程序相匹配的业务逻辑代码,并处理相应的权限广播人员的判断,工作量较大,耗费大量人力资源,导致业务分发效率较低;其次,由于多个从应用程序的业务代码耦合在一起,当一个从应用程序的业务逻辑代码出现错误时,势必会影响其他应用程序的运行
[0039] (1) This invention constructs a WebSocket-based service dispatcher that includes four tools: controller, service, broadcaster and frequency generator. Before the WebSocket call, the data communication between the server and the client is segmented, sorted and judged according to the four tools: control, service, broadcast and frequency. This standardizes and orders each communication between the two ends, and optimizes the various functions required for communication as much as possible, making the communication more secure, efficient and hierarchical. It also strictly controls the bandwidth used in the communication and lays the technical foundation for the reuse of a set of fixed connection attributes formed by the configuration of the four tools.
Smart Images

Figure CN116866326B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of network communication technology, and more specifically, to a WebSocket-based service dispatcher and a method for optimizing WebSocket connections. Background Technology
[0002] With the rapid development of the internet age, more and more internet technologies are being applied to people's lives, giving rise to countless application services that greatly facilitate people's work and life. Most of these application services use the HTTP protocol for communication. This protocol distinguishes between client and server, and the two ends communicate in a simplex manner, meaning that only the client can request the server, and the server cannot actively maintain communication with the client. This makes it impossible to meet the point-to-point real-time communication needs between the two ends. Data synchronization between the client and server is usually achieved by periodically polling to increase bandwidth resources, which often comes at a significant cost. WebSocket emerged to address this issue, as it can maintain a persistent long-lived connection between the client and server, enabling communication between the two ends at a lower cost. Therefore, the development of components based on WebSocket that can group and distribute data according to business logic for separate processing is extremely important.
[0003] Currently, most PC applications on the market are developed based on the C / S and B / S models. However, with the continuous development of the Internet and the rise of the Web, the convenient and fast B / S (browser / server) model has become a unicorn, with a market share far exceeding that of C / S. WebSocket, which is built on B / S, is also being used by more and more application developers. It is favored by application developers for its lower overhead, stronger real-time performance, and better multi-dimensional support. Its resource-saving, stable, robust, and scalable characteristics make it extremely irreplaceable.
[0004] However, when the server communicates with the client via WebSocket in existing technologies, developers usually need to develop business logic code that matches each slave application separately and handle the judgment of the corresponding permission broadcasters. This is a large workload and consumes a lot of human resources, resulting in low business distribution efficiency. Secondly, since the business code of multiple slave applications is coupled together, when the business logic code of one slave application has an error, it will inevitably affect the operation of other applications. Summary of the Invention
[0005] In response to at least one defect or improvement requirement in the prior art mentioned in the background section, the present invention provides a WebSocket-based service dispatcher and a method for optimizing WebSocket connections, which at least improves the efficiency of the server in establishing communication connections with the client via WebSocket.
[0006] To achieve the above objectives, in a first aspect, the present invention provides a WebSocket-based service dispatcher, comprising:
[0007] The controller is used to determine the connection permissions of clients that call WebSocket;
[0008] The business unit is used to perform hierarchical decomposition of the business according to the business logic to form a business topology tree when the controller determines that the user has connection permission, and to determine the user permission and domain permission.
[0009] The broadcaster is used to filter out clients that need to broadcast communication based on the user permissions and domain permissions determined by the service.
[0010] A frequency converter is used to limit the time of this communication connection based on the connection frequency of the broadcast communication.
[0011] Furthermore, the business unit starts from the root node of the business topology tree, and is hierarchically classified according to the size of the business, and can name each node of each topology branch according to the characteristics of the business.
[0012] Furthermore, the broadcast communication includes private broadcast communication and group broadcast communication;
[0013] The private broadcast communication is for information communication with a single client;
[0014] The group broadcast communication is for information communication with at least two clients.
[0015] Furthermore, the group broadcast communication includes partial group broadcast communication and all group broadcast communication;
[0016] The aforementioned group broadcast communication is information communication with a subset of clients within a preset range;
[0017] The aforementioned group broadcast communication refers to information communication with all clients within a preset range.
[0018] Furthermore, the time limit restriction includes timed connections and untimed connections;
[0019] The timed connection is a connection whereby the server initiates the termination of the information communication connection with the client after a preset time.
[0020] The "irregular connection" refers to the connection between the server and the client without a preset time limit for information communication.
[0021] Secondly, the present invention provides a method for optimizing WebSocket connections, including:
[0022] Perform connection permission checks on clients that call WebSocket;
[0023] When it is determined that the user has connection permission, the business logic is used to decompose the business into layers to form a business topology tree, and user permissions and domain permissions are judged.
[0024] Based on the determined user permissions and domain permissions, the clients that need to broadcast communication are selected;
[0025] The time limit for this communication connection is imposed based on the connection frequency of the broadcast communication.
[0026] Based on the above four steps, a fixed set of WebSocket connection attributes is constructed;
[0027] The established set of fixed WebSocket connection properties are reused to directly connect to subsequent WebSocket connections that are determined to have the same properties.
[0028] Furthermore, it also includes starting from the root node of the business topology tree, hierarchically classifying the associations according to the business size, and naming each node of each topology branch according to the business characteristics.
[0029] Furthermore, the broadcast communication includes private broadcast communication and group broadcast communication;
[0030] The private broadcast communication is for information communication with a single client;
[0031] The group broadcast communication is for information communication with at least two clients.
[0032] Furthermore, the group broadcast communication includes partial group broadcast communication and all group broadcast communication;
[0033] The aforementioned group broadcast communication is information communication with a subset of clients within a preset range;
[0034] The aforementioned group broadcast communication refers to information communication with all clients within a preset range.
[0035] Furthermore, the time limit restriction includes timed connections and untimed connections;
[0036] The timed connection is a connection whereby the server initiates the termination of the information communication connection with the client after a preset time.
[0037] The "irregular connection" refers to the connection between the server and the client without a preset time limit for information communication.
[0038] In summary, compared with the prior art, the above-described technical solutions conceived by this invention can achieve the following beneficial effects:
[0039] (1) This invention constructs a WebSocket-based service dispatcher that includes four tools: controller, service, broadcaster and frequency generator. Before the WebSocket call, the data communication between the server and the client is segmented, sorted and judged according to the four tools: control, service, broadcast and frequency. This standardizes and orders each communication between the two ends, and optimizes the various functions required for communication as much as possible, making the communication more secure, efficient and hierarchical. It also strictly controls the bandwidth used in the communication and lays the technical foundation for the reuse of a set of fixed connection attributes formed by the configuration of the four tools.
[0040] (2) When the server communicates with the client via WebSocket, the present invention records and reuses a set of fixed connection attributes configured sequentially by the aforementioned four tools, thereby avoiding repeated configuration, improving the efficiency of WebSocket connection and business distribution, making communication more secure, efficient and hierarchical, and saving bandwidth overhead. Attached Figure Description
[0041] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0042] Figure 1 A flowchart illustrating a method for optimizing WebSocket connections provided in an embodiment of the present invention;
[0043] Figure 2 A business structure flowchart provided for embodiments of the present invention;
[0044] Figure 3 A flowchart illustrating the usage of internal tools in the service distributor provided in this embodiment of the invention. Detailed Implementation
[0045] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.
[0046] The terms "comprising" or "having," and any variations thereof, in the specification, claims, or accompanying drawings of this application are intended to cover a non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the steps or units listed, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such processes, methods, products, or apparatus.
[0047] refer to Figure 2 and Figure 3 In one embodiment, a WebSocket-based service dispatcher includes four tools: a controller, a service provider, a broadcaster, and a frequency generator.
[0048] Controller: The controller is a switch that checks the connection permissions (calling permissions) of the user calling WebSocket (actually the client used by the user). It is the priority condition for the four tools. If no permission is granted, no configuration of other tools is required, the process ends directly and the connection is closed; if permission is granted, the configuration of the next tool begins.
[0049] Business Unit: The business unit is the most important core part. Based on the specific business characteristics, it decomposes the business into layers to form a business topology tree. Starting from the root node, it is hierarchically classified according to the size of the business and the relationships. Not all topology branches need to have the same number of nodes. The nodes are allocated according to the specific business. Each node in each branch can be named according to the business. Each topology branch can be given a unique name according to its business characteristics so as to form a special configuration name for use.
[0050] Broadcaster: A broadcaster refers to a specific client object initiated by the server. It relies on the business logic to determine the specific user and domain permissions to filter the information communication based on user characteristics. This tool is divided into private broadcasts and group broadcasts. Private broadcasts are used for communication with individual users based on business needs, while group broadcasts are further divided into partial group broadcasts and all group broadcasts. Partial group broadcasts are typically used for business logic communication, while all group broadcasts are used when business logic requires communication with all users. Additionally, it's worth mentioning that the heartbeat connection in WebSocket is an example of an all-group broadcast. It's typically set to be sent every five minutes, initiated by the client and sent to the server to test the connection's integrity. If the connection is faulty, a reconnection request is sent.
[0051] Frequency Setter: A frequency setter refers to the time limit for the connection between the client and server. It is a product of combining with scheduled tasks. Frequency setters are divided into two types: timed and untimed. A timed frequency setter means that when the set time is reached, the server will actively initiate the termination of the connection with the client. This termination is one-way and irreversible. To restore the connection, a reconnection needs to be initiated through the service dispatcher. An untimed connection, on the other hand, is a permanent connection with no time limit, lasting until the client closes the connection or the server terminates the service. This tool aims to allow for flexible control of long-lived connections based on specific business needs, saving bandwidth resources.
[0052] The WebSocket-based service dispatcher provided by this invention comprises four tools: a controller, a service provider, a broadcaster, and a frequency generator. This allows applications to be configured using these four tools before transmitting data via WebSocket. The controller determines whether the current user has permission to call the service; for example, if a guest logs in and no push notification is needed, the controller can be set to "no" to interrupt the connection. The service provider is the most crucial core component, hierarchically categorizing specific business logic into a topology tree, which can be decomposed into the smallest unit based on the specific business requirements. The broadcaster determines the broadcast method for individuals or groups based on the communication recipients. The frequency generator determines whether to establish a timed or untimed long connection based on the communication frequency. In this way, before the WebSocket call, the data communication between the server and client is segmented, organized, and judged using these four tools, standardizing and ordering each communication between the two ends. This optimizes and improves the various functions required for communication, making the communication more secure, efficient, and hierarchical, while strictly controlling the bandwidth used in the communication. Furthermore, it lays the technical foundation for the subsequent reuse of a fixed set of connection attributes configured by these four tools.
[0053] refer to Figure 1 and Figure 3In another embodiment, a method for optimizing a WebSocket connection mainly includes the following steps.
[0054] Step 1: Check the connection permissions of the client calling WebSocket. Specifically, the controller first checks whether the client calling WebSocket has the necessary permissions. If not, the aforementioned business dispatcher returns the client to the server to continue executing its own thread and closes the WebSocket connection. If the client has the necessary permissions, proceed to the next step.
[0055] Step 2: When the controller in Step 1 determines that it has connection permission, the business unit decomposes the business into layers according to the business logic to form a business topology tree. The specific topology branches form named records, and user permissions and domain permissions are judged.
[0056] Step 3: The broadcaster filters out the clients that need to broadcast communication based on the user permissions and domain permissions determined by the service in Step 2.
[0057] Step 4: The frequency converter sets a time limit for this communication connection based on the connection frequency of the broadcast communication. Specifically, the connection frequency of the broadcast determines whether it is a persistent or non-persistent connection.
[0058] Step 5: Based on the four operations described in Steps 1 to 4, construct a fixed set of WebSocket connection attributes. Specifically, the service dispatcher will configure a fixed set of connection attributes according to the four tools mentioned above and record them.
[0059] Step 6: Reuse the established set of fixed WebSocket connection attributes to directly connect to subsequent WebSocket connections identified as having the same attributes. Specifically, if there are subsequent connections with the same attributes, they can be directly connected using the set of fixed connection attributes formed in Step 5, without needing to redetermine the attributes based on the business dispatcher.
[0060] Figure 2 This is merely the smallest unit of communication between the server and the client. In real-world applications, one server might correspond to multiple client connections. When the server uses WebSocket with each client, it invokes the business dispatcher. The business dispatcher configures a fixed set of connection attributes based on the four tools mentioned above and records them. Subsequently, if a connection with the same attributes is needed, it can be established directly through this configuration without having to re-determine the attributes based on the business dispatcher. For a detailed technical description of the four tools—controller, business unit, broadcaster, and frequency generator—please refer to the previous embodiment; they will not be repeated here.
[0061] When the server communicates with the client via WebSocket, this invention records and reuses a set of fixed connection attributes configured sequentially by the aforementioned four tools, thereby avoiding redundant configuration, improving the efficiency of WebSocket connection and business distribution, making communication more secure, efficient, and hierarchical, and saving bandwidth overhead.
[0062] It should be noted that the flowcharts or block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, or computer program products according to various embodiments of this disclosure. In this regard, each block in the flowchart or block diagram may represent a module, segment, or portion of code, which includes one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. Furthermore, it should be noted that each block in the block diagram or flowchart, and combinations of blocks in the block diagram or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0063] Those skilled in the art will understand that the features described in the various embodiments and / or claims of this disclosure can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in this disclosure. In particular, the features described in the various embodiments and / or claims of this disclosure can be combined and / or combined in various ways without departing from the spirit and teachings of this disclosure, and all such combinations and / or combinations fall within the scope of this disclosure.
[0064] Although this disclosure has been shown and described with reference to specific exemplary embodiments thereof, those skilled in the art will understand that various changes in form and detail may be made to this disclosure without departing from the spirit and scope of the disclosure as defined by the appended claims and their equivalents. Therefore, the scope of this disclosure should not be limited to the above embodiments, but should be defined not only by the appended claims, but also by their equivalents.
Claims
1. A WebSocket-based service dispatcher, characterized in that, include: The controller is used to determine the connection permissions of clients that call WebSocket; The business unit is used to perform hierarchical decomposition of the business according to the business logic to form a business topology tree when the controller determines that the user has connection permission, and to determine the user permission and domain permission. The broadcaster is used to filter out clients that need to broadcast communication based on the user permissions and domain permissions determined by the service. The frequency generator is used to limit the time of this communication connection based on the connection frequency of the broadcast communication; wherein, the service distributor is also configured to construct and record a set of fixed WebSocket connection attributes based on the configuration output of the controller, service unit, broadcaster and frequency generator, and reuse the set of fixed WebSocket connection attributes to directly connect to subsequent WebSocket connections judged to have the same attributes.
2. The service distributor as described in claim 1, characterized in that, The business unit starts from the root node of the business topology tree, and is hierarchically classified according to the size of the business. Each node of each topology branch can be named according to the characteristics of the business.
3. The service distributor as described in claim 1, characterized in that, The broadcast communications include private broadcast communications and group broadcast communications; The private broadcast communication is for information communication with a single client; The group broadcast communication is for information communication with at least two clients.
4. The service distributor as described in claim 3, characterized in that, The group broadcast communication includes partial group broadcast communication and all group broadcast communication; The aforementioned group broadcast communication is information communication with a subset of clients within a preset range; The aforementioned group broadcast communication refers to information communication with all clients within a preset range.
5. The service distributor as described in claim 1, characterized in that, The time limit restrictions include timed connections and untimed connections; The timed connection is a connection whereby the server initiates the termination of the information communication connection with the client after a preset time. The "irregular connection" refers to the connection between the server and the client without a preset time limit for information communication.
6. A method for optimizing WebSocket connections, characterized in that, include: Perform connection permission checks on clients that call WebSocket; When it is determined that the user has connection permission, the business logic is used to decompose the business into layers to form a business topology tree, and user permissions and domain permissions are judged. Based on the determined user permissions and domain permissions, the clients that need to broadcast communication are selected; The time limit for this communication connection is imposed based on the connection frequency of the broadcast communication. Based on the above four steps, a fixed set of WebSocket connection attributes is constructed; The established set of fixed WebSocket connection properties are reused to directly connect to subsequent WebSocket connections that are determined to have the same properties.
7. The method for optimizing WebSocket connections as described in claim 6, characterized in that, It also includes starting from the root node of the business topology tree, hierarchically classifying and associating based on business size, and naming each node of each topology branch according to business characteristics.
8. The method for optimizing WebSocket connections as described in claim 6, characterized in that, The broadcast communications include private broadcast communications and group broadcast communications; The private broadcast communication is for information communication with a single client; The group broadcast communication is for information communication with at least two clients.
9. The method for optimizing WebSocket connections as described in claim 8, characterized in that, The group broadcast communication includes partial group broadcast communication and all group broadcast communication; The aforementioned group broadcast communication is information communication with a subset of clients within a preset range; The aforementioned group broadcast communication refers to information communication with all clients within a preset range.
10. The method for optimizing WebSocket connections as described in claim 6, characterized in that, The time limit restrictions include timed connections and untimed connections; The timed connection is a connection whereby the server initiates the termination of the information communication connection with the client after a preset time. The "irregular connection" refers to the connection between the server and the client without a preset time limit for information communication.
Citation Information
Patent Citations
Multi-screen linkage method and system
CN111221490A
Conference message pushing method, conference server and electronic equipment
CN115865874A