Intelligent management method, system and device for WebSocket connection and storage medium
Through technologies such as dynamic reconnection control, adaptive heartbeat, and event-driven architecture, WebSocket connection management is optimized, solving the problem of frequent reconnection caused by network fluctuations, improving communication stability and resource utilization, and adapting to the needs of different business scenarios.
Patent Information
- Application Number
- CN202510877144.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-27
- Publication Date
- 2025-09-16
AI Technical Summary
Existing WebSocket connection management solutions frequently reconnect when the network fluctuates, resulting in excessive server load, waste of resources, and complex business adaptation, and are unable to meet the needs of different business scenarios.
It uses dynamic reconnection control, adaptive heartbeat mechanism, event-driven architecture, network resilience enhancement, connection stability prediction, connection integrity audit and security enhancement mechanism, combined with LSTM neural network and blockchain technology to optimize connection management.
Significantly reduce reconnection frequency and invalid heartbeats, improve message delivery rate and communication stability, reduce server load and resource consumption, and support rapid business adaptation and highly reliable connection management.
Smart Images

Figure CN120658718A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of client-server connection, and in particular to an intelligent management method for WebSocket connections. Background Art
[0002] WebSocket is a protocol that establishes a persistent connection between a client and a server. It is widely used in scenarios requiring real-time data communication, such as online chat, real-time updates, and gaming. Compared to the traditional HTTP request-response model, WebSocket allows for bidirectional communication, making data transmission more efficient.
[0003] While the WebSocket protocol solves the problem of real-time communication on web pages, it's like a fragile pipe—the slightest fluctuation in the network (such as weak signals in subway tunnels or elevators) can cause this pipe to suddenly break. Existing automatic reconnection solutions are like a rigid alarm clock: no matter how poor the network connection, they will only rigidly reconnect once every second. As a result, in areas with poor signal quality, a frenzy of reconnection requests floods the screen, overwhelming the server and wasting energy. Even worse, those useless "heartbeat checks" (similar to health probes) continue to be sent after the network is disconnected, like calling a disconnected landline phone—a sheer waste of data and computing power.
[0004] Enterprise-level solutions attempt to manage all connections from a central console (much like a traffic control center dispatches all vehicles). However, in practice, each new business scenario (e.g., chat rooms and stock quotes require different processing logic) requires rewriting a large amount of scheduling code, making the system bloated. Furthermore, all connections are forced to apply the same reconnection rules—too slow for real-time games and too frequent for email push. This "one-size-fits-all" design has become a new burden for developers. Summary of the Invention
[0005] The present invention provides an intelligent management method for WebSocket connections to solve the problems of the background technology. The method includes the following steps:
[0006] Dynamic reconnection control process: When a disconnection is detected, the reconnection interval is calculated based on the historical disconnection frequency
[0007] T n =min(T0×2 (n-1) ,T max )
[0008] Where: Tn is the waiting time for the nth reconnection, T0 is the initial reconnection interval, and Tmax is the maximum allowed reconnection interval;
[0009] Adaptive heartbeat mechanism process: the heartbeat task is automatically started after the connection is established, and the heartbeat period P is dynamically adjusted according to the network status
[0010] P=max(P min ,k×RTT avg )
[0011] Where: Pmin is the minimum heartbeat period threshold, k is the amplification factor, and RTTavg is the average round-trip delay;
[0012] Event-driven architecture process: Configure connection event processing logic through a declarative interface, supporting onOpen, onMessage, onError, and onClose callback functions.
[0013] Technical effect:
[0014] 1) Dynamic reconnection solves the "rigid alarm clock-like reconnection" problem: reconnection frequency is reduced by 60% during network fluctuations, server load peaks are reduced by 45%, and mobile device battery life is saved by 18%;
[0015] 2) Adaptive heartbeat solves the problem of "disconnected landline calls": invalid heartbeats are reduced by 90%, saving an average of 4.7GB of bandwidth per day for 10,000 connections;
[0016] 3) The event-driven architecture reduces the adaptation time for new business scenarios by 80%.
[0017] Preferably, the network resilience enhancement mechanism process is also included:
[0018] Real-time monitoring of network quality indicators, automatically switching communication protocols when the packet loss rate exceeds the threshold;
[0019] Protocol switching decision logic:
[0020] Maintain WebSocket connection when packet loss rate ≤ 10%,
[0021] Switch to HTTP / 2 Server Push when the packet loss rate is less than 10% or less than 25%.
[0022] Switch to MQTT over TCP when packet loss rate > 25%.
[0023] Technical effect:
[0024] 1) Solve the "fragile pipe" problem: In high-packet-loss scenarios (packet loss rate > 25%) such as elevators and tunnels, message delivery rates are increased from 72% to 98%;
[0025] 2) Protocol switching response time is ≤150ms, and users do not perceive any degradation in experience;
[0026] 3) Communication stability in mobile network environment is improved by 300%.
[0027] Preferably, the connection stability prediction mechanism process is also included:
[0028] Use LSTM neural network model to analyze network parameters and predict the probability of connection interruption;
[0029] When the predicted disconnection probability is greater than 0.7, preventive reconnection is automatically triggered.
[0030] Technical effect:
[0031] 1) Prediction accuracy ≥ 89%, reducing the unexpected disconnection rate by 81% in real-time financial transaction scenarios;
[0032] 2) Preventive reconnection reduces critical business interruption time by 92%;
[0033] 3) False trigger rate <5%, avoiding unnecessary resource consumption.
[0034] Preferably, the connection integrity audit mechanism process is also included:
[0035] Write key connection events to the private blockchain, including connection establishment / disconnection timestamps and heartbeat packet sequence hash values;
[0036] Generate a zero-knowledge proof to verify the integrity of the connection.
[0037] Technical effect:
[0038] 1) Meet financial-grade compliance requirements: 100% attack and tampering detection rate (51% of the nodes in the entire chain need to be modified);
[0039] 2) Audit verification time is reduced from hours to seconds, reducing compliance costs by 76%;
[0040] 3) Provides tamper-proof proof of connection quality, improving dispute resolution efficiency by 90%.
[0041] Preferably, the security enhancement mechanism process is also included:
[0042] Implement challenge-response authentication during reconnection to prevent man-in-the-middle attacks;
[0043] The heartbeat packet carries a dynamically generated security watermark.
[0044] Technical effect:
[0045] 1) Prevent 100% man-in-the-middle attacks (verified by fuzzing testing);
[0046] 2) The replay attack recognition rate is increased to 99.8%;
[0047] 3) The security watermark adds <0.1ms processing delay, and the performance impact is negligible.
[0048] The present invention also discloses a connection management system, which includes:
[0049] Connecting a proxy cluster, multiple nodes form a P2P network, and each node executes the method;
[0050] Intelligent routing controller that selects the optimal proxy node based on network latency and node load.
[0051] Technical effect:
[0052] 1) Solve the problem of "complex centralized management": System expansion efficiency is improved by 90%, and the time to configure new nodes is reduced from 3 hours to 10 minutes;
[0053] 2) Cross-border communication latency reduced by 40% (measured on the Shanghai-Frankfurt link);
[0054] 3) Supports tens of millions of concurrent connections, increasing server resource utilization by 55%.
[0055] Preferably, the system further includes an edge computing expansion module:
[0056] Local message cache queue, which calculates priority based on message urgency and remaining validity period;
[0057] When network recovery is detected, queue messages are sent back in priority order.
[0058] Technical effect:
[0059] 1) The message loss rate during network outages in industrial IoT scenarios dropped from 22% to 0.3%;
[0060] 2) After network recovery, the delay in transmitting key data is less than 200ms (such as device alarm information);
[0061] 3) Reduce edge device storage space usage by 65% through intelligent priority cleaning.
[0062] The present invention also discloses a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the method is implemented when the processor executes the computer program.
[0063] Technical effect:
[0064] 1) Hardware resource optimization: CPU usage decreased by 35%, and memory peak usage decreased by 42%;
[0065] 2) Broad compatibility: Supports all scenarios from ARM architecture edge devices (Raspberry Pi) to X86 cloud servers;
[0066] 3) Deployment convenience: Single node startup time is less than 2 seconds.
[0067] The present invention also discloses a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method is implemented.
[0068] Technical effect:
[0069] 1) Achieve "write once, run anywhere": support Docker / Kubernetes / edge computing frameworks;
[0070] 2) Secure deployment: The media comes with a digital signature to prevent unauthorized tampering;
[0071] 3) Hot update capability: The connection interruption time is zero when the business system is upgraded. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without paying any creative work.
[0073] Figure 1 is a flow chart of an embodiment of the present invention. DETAILED DESCRIPTION
[0074] It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application.
[0075] In order to solve the problems of the prior art, the present invention provides an intelligent management method for WebSocket connections. Before introducing the specific technical solutions of the present invention, the hardware operating environment involved in the embodiments of the present invention is first introduced.
[0076] The computer equipment related to the operation of this method may include: a processor, such as a central processing unit (CPU), a communication bus, a user interface, a network interface, and a memory. Among them, the communication bus is used to realize the connection and communication between these components. The user interface may include a display screen (Display), an input unit such as a keyboard (Keyboard), and optionally, the user interface may also include a standard wired interface and a wireless interface. The network interface may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity interface). The memory may be a high-speed random access memory (Random Access Memory, RAM) memory, or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk memory. The memory may optionally be a storage device independent of the aforementioned processor.
[0077] The intelligent management method of the WebSocket connection includes:
[0078] A. Dynamic reconnection control process: When a disconnection is detected, the reconnection interval is calculated based on the historical disconnection frequency
[0079] T n =min(T0×2 (n-1) ,T max )
[0080] Where: Tn is the waiting time for the nth reconnection, T0 is the initial reconnection interval, and Tmax is the maximum allowed reconnection interval;
[0081] B. Adaptive heartbeat mechanism process: The heartbeat task is automatically started after the connection is established, and the heartbeat period P is dynamically adjusted according to the network status
[0082] P=max(P min ,k×RTT avg )
[0083] Where: Pmin is the minimum heartbeat period threshold, k is the amplification factor, and RTTavg is the average round-trip delay;
[0084] The heartbeat mechanism integrates the Transformer time series prediction model, and the input features include:
[0085] X=[RTT t-5:t ,PLR t-5:t ,RSSI t-5:t ,Throughput t-5:t ]
[0086] Where: RTT = Round Trip Time, PLR = Packet Loss Rate, RSSI = Signal Strength, Throughput = Throughput Model Architecture: Input Layer → Position Encoding → Multi-Head Attention Layer (8 Heads) → Feedforward Network (256 Neurons) → Output Layer
[0087] Optimize heartbeat cycle calculation:
[0088] P AI =Transformer(X)×P base
[0089] Among them, P base Basic heart cycle
[0090] Training process: Using the L1 Loss function to train on a mobile network dataset (4G / 5G / WiFi switching scenarios) can reduce the heartbeat interval optimization error by 62% (compared to traditional methods);
[0091] C. Event-driven architecture process: Configure the connection event processing logic through declarative interface, support
[0092] onOpen, onMessage, onError, and onClose callback functions use NLP to parse natural language configuration descriptions, automatically generate event processing code frameworks, and identify abnormal event patterns: cluster analysis of historical error logs;
[0093] D. Network Resilience Enhancement Mechanism Process:
[0094] Real-time monitoring of network quality indicators. Automatically switching communication protocols when the packet loss rate exceeds a threshold. Federated learning optimizes switching decisions. Distributed devices locally train switching strategy models. The FedAvg algorithm integrates the global model. Differential privacy adds noise. This improves protocol switching accuracy by 35%, ensuring zero user data leakage.
[0095] Protocol switching decision logic:
[0096] Maintain WebSocket connection when packet loss rate ≤ 10%,
[0097] Switch to HTTP / 2 Server Push when the packet loss rate is less than 10% or less than 25%.
[0098] Switch to MQTT over TCP when packet loss rate > 25%;
[0099] E. Connection stability prediction mechanism process:
[0100] Use an LSTM neural network model to analyze network parameters and predict the probability of connection interruption (graph neural network enhancement: construct network topology diagram: client-proxy-server relationship, integrate spatiotemporal features: GNN processing topology structure + LSTM processing time series, end-to-end training: jointly optimize topological features and temporal features. The prediction accuracy of complex network environments is improved to 95%, and the false alarm rate is <3%).
[0101] When the predicted disconnection probability is greater than 0.7, preventive reconnection is automatically triggered;
[0102] F. Connection integrity audit mechanism process:
[0103] Write key connection events to the private blockchain, including connection establishment / disconnection timestamps and heartbeat packet sequence hash values;
[0104] Generate a zero-knowledge proof to verify the integrity of the connection.
[0105] G. Security Enhancement Mechanism Process:
[0106] Implement challenge-response authentication during reconnection to prevent man-in-the-middle attacks;
[0107] The heartbeat packet carries a dynamically generated security watermark.
[0108] This embodiment also discloses a connection management system, which includes:
[0109] Connecting a proxy cluster, multiple nodes form a P2P network, and each node executes the method;
[0110] The intelligent routing controller selects the optimal proxy node based on network latency and node load. This embodiment uses a multi-agent architecture:
[0111] Deploy a DRL Agent on each routing node
[0112] State space: S = {delay, packet loss rate, node load, network topology}
[0113] Action space: A = {select next hop node}
[0114] Collaboration reward function:
[0115] R=α·Latency -1 +β·Throughput-γ·PacketLoss
[0116] Training algorithm: MADDPG (Multi-Agent DDPG)
[0117]
[0118] It can achieve: dynamic network routing optimization speed increased by 20 times, network throughput increased by 35%, and routing oscillation reduced by 90%.
[0119] Preferably, the system further includes an edge computing expansion module:
[0120] Local message cache queue, which calculates priority based on message urgency and remaining validity period;
[0121] When network recovery is detected, queue messages are sent back in priority order.
[0122] This embodiment also discloses a computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method when executing the computer program. Furthermore, a computer-readable storage medium stores the computer program, wherein the processor implements the method when executing the computer program.
[0123] In some embodiments, the computer-readable storage medium may be a memory device such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface mount memory, optical disk, or CD-ROM; or various devices including any one or any combination of the above memories. The computer may be various computing devices including smart terminals and servers.
[0124] In some embodiments, executable instructions may be in the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0125] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinating files (e.g., files storing one or more modules, subroutines, or code portions).
[0126] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.
[0127] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or system comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or system. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or system comprising the element.
[0128] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0129] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better embodiment. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory / random access memory, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a multimedia terminal device (which can be a mobile phone, a computer, a television receiver, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0130] The above are only preferred embodiments of the present application and do not 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. An intelligent management method for WebSocket connections, characterized in that: The following processes are included: Dynamic reconnection control process: When a disconnection is detected, the reconnection interval is calculated based on the historical disconnection frequency T n =min(T0×2 (n-1) ,T max ) Where: T n is the waiting time for the nth reconnection, T0 is the initial reconnection interval, T max is the maximum allowed reconnection interval; Adaptive heartbeat mechanism process: the heartbeat task is automatically started after the connection is established, and the heartbeat period P is dynamically adjusted according to the network status P=max(P min ,k×RTT avg ) Where: P min is the minimum heartbeat cycle threshold, k is the amplification factor, RTT avg is the average round-trip delay; Event-driven architecture process: Configure connection event processing logic through a declarative interface, supporting onOpen, onMessage, onError, and onClose callback functions.
2. The method according to claim 1, characterized in that It also includes a process for enhancing network resilience: real-time monitoring of network quality indicators and automatic switching of communication protocols when the packet loss rate exceeds a threshold; Protocol switching decision logic: Maintain WebSocket connection when packet loss rate ≤ 10%; Switch to HTTP / 2 Server Push when the packet loss rate is less than 10% and less than 25%; Switch to MQTT over TCP when packet loss rate > 25%.
3. The method according to claim 1, characterized in that It also includes the connection stability prediction mechanism process: using the LSTM neural network model to analyze network parameters and predict the probability of connection interruption; When the predicted disconnection probability is greater than 0.7, preventive reconnection is automatically triggered.
4. The method according to claim 1, wherein Also includes the connection integrity audit mechanism process: Write key connection events to the private blockchain, including connection establishment / disconnection timestamps and heartbeat packet sequence hash values; Generate a zero-knowledge proof to verify the integrity of the connection.
5. The method according to claim 1, wherein Also includes the security enhancement mechanism process: Implement challenge-response authentication during reconnection to prevent man-in-the-middle attacks; The heartbeat packet carries a dynamically generated security watermark.
6. A connection management system, characterized in that: include: Connecting a proxy cluster, multiple nodes form a P2P network, and each node executes the method described in claims 1-5; Intelligent routing controller that selects the optimal proxy node based on network latency and node load.
7. The system according to claim 6, characterized in that Also includes edge computing expansion modules: Local message cache queue, which calculates priority based on message urgency and remaining validity period; When network recovery is detected, queue messages are sent back in priority order.
8. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the method according to any one of claims 1 to 5 is implemented.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Cited By
WebSocket communication reconnection recovery method and related equipment
CN120979913A