AI application front-end and back-end communication protocol implementation method based on WebSocket
By monitoring historical performance data of the WebSocket communication link and using a density clustering model to identify network status, and combining frame length and task priority to generate an adaptive communication protocol, the problem of balancing low latency and high reliability in WebSocket applications is solved, achieving optimal allocation of network resources and maximizing user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN RUIWANG YUNLIAN TECH CO LTD
- Filing Date
- 2025-12-20
- Publication Date
- 2026-04-21
AI Technical Summary
WebSocket communication struggles to balance low latency and high reliability in AI applications within complex network environments. Existing technologies lack the ability to predict network state patterns, making it difficult to meet the personalized communication quality requirements of AI applications.
By monitoring historical performance data of the WebSocket communication link, a density clustering model is used to identify network status. An adaptive communication protocol is generated by combining frame length and task priority, and the transmission mode is dynamically adjusted to adapt to different network statuses and task requirements.
It achieves adaptive control reliability of WebSocket communication in AI application scenarios, improves transmission efficiency and reliability, and meets the personalized communication quality requirements of AI applications.
Smart Images

Figure CN121907397A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method for implementing a front-end and back-end communication protocol for AI applications based on WebSocket, belonging to the field of computer communication technology. Background Technology
[0002] Currently, although the WebSocket protocol provides full-duplex communication capabilities, in complex network environments, especially for AI applications with high real-time requirements such as real-time speech recognition and interactive AI dialogue, fixed frame processing strategies are difficult to balance low latency and high reliability. Existing technologies mostly make reactive adjustments based on real-time network indicators, lacking predictive judgment of network state patterns, and are unable to meet the personalized communication quality requirements of AI applications.
[0003] Therefore, WebSocket communication lacks reliability in adaptive control within AI application scenarios. Summary of the Invention
[0004] This invention provides a method for implementing a front-end and back-end communication protocol for AI applications based on WebSocket, the main purpose of which is to improve the reliability of adaptive control of WebSocket communication in AI application scenarios.
[0005] To achieve the above objectives, this invention provides a method for implementing a front-end and back-end communication protocol for AI applications based on WebSocket, comprising: Monitor historical performance data of the WebSocket communication link within a continuous time window, wherein the historical performance data includes transmission delay, packet loss rate, and frame length; The transmission delay and the packet loss rate are combined into a two-dimensional feature matrix, and the two-dimensional feature matrix is input into a density clustering model so that the network state label corresponding to the two-dimensional feature matrix is output through the density clustering model. Based on the frame length and the network status label, the data transmission pattern of the WebSocket communication link is determined; The WebSocket communication management module in the AI supply backend receives data packets sent from the AI application frontend and extracts the task priority identifier from the data packets. Based on the task priority identifier, the front-end and back-end communication protocol for generating the data packet is generated using the data transmission format.
[0006] Optionally, before outputting the network state labels corresponding to the two-dimensional feature matrix through the density clustering model, the method further includes: Collect parameter tuning samples on the WebSocket communication link, wherein the parameter tuning samples include historical latency and historical packet loss rate; The historical latency and the historical packet loss rate are normalized respectively to obtain normalized latency and normalized packet loss rate; Determine the sample points corresponding to each pair of normalized delay and normalized packet loss rate; The fourth nearest neighbor distance for each sample point is calculated using the k-distance method. Sort the fourth nearest neighbor distances from smallest to largest to generate the k-distance curve of the fourth nearest neighbor distance; Find the inflection point of the k-distance curve; The neighborhood radius of the density clustering model is inversely calculated using the normalized distance value corresponding to the inflection point of the curve. Set a threshold for the number of spatial neighbors in the density clustering model; Based on the density clustering model, calculate the silhouette coefficient and noise rate for each spatial neighbor number threshold; Based on the silhouette coefficient and the noise rate, the minimum number of neighbors for the density clustering model is determined; The neighborhood radius and the minimum number of neighbors are deployed into the density clustering model.
[0007] Optionally, the step of using the normalized distance value corresponding to the inflection point of the curve to inversely deduce the neighborhood radius of the density clustering model includes: Based on the normalized distance value corresponding to the inflection point of the curve, the neighborhood radius of the density clustering model is calculated using the following formula: ; ; ; ; in, Represents the neighborhood radius. This represents the dimensionless scaling factor. Indicates the maximum range of delay values. This represents the minimum range of delay values. This represents the denormalized delay error. This represents the maximum range of packet loss rate. This represents the minimum range of packet loss rate. This represents the inverse normalized packet loss rate error. Represents the normalized distance value. The standard deviation representing historical lag The standard deviation of the historical packet loss rate.
[0008] Optionally, determining the data transmission format of the WebSocket communication link based on the frame length and the network status label includes: When the label in the network status label is high latency and high packet loss mode, based on the frame length, the anti-interference transmission mode of the WebSocket communication link is triggered. The anti-interference transmission mode refers to the mode of splitting the data packet into multiple subframes no larger than the maximum transmission unit and adding redundant check information to each subframe. When the label in the network status label is low latency and low packet loss mode, the high-speed transmission mode of the WebSocket communication link is triggered based on the frame length. The high-speed transmission mode refers to the mode of merging data packets into long frames no larger than the maximum transmission unit. The anti-interference transmission mode and the high-speed transmission mode are used as data transmission modes.
[0009] Optionally, the step of generating the front-end and back-end communication protocol of the data packet using the data transmission format based on the task priority identifier includes: When the data transmission mode is anti-interference transmission mode and the task priority identifier is high priority, the anti-interference transmission mode is converted to super anti-interference mode. The super anti-interference mode and the task priority identifier are encapsulated into a WebSocket extended frame, wherein the WebSocket extended frame includes frame mode, maximum frame length, subframe length, redundancy level, retransmission timeout flag, priority overlay flag and application layer load. When the data transmission mode is an anti-interference transmission mode and the task priority identifier is a low priority, the anti-interference transmission mode and the task priority identifier are encapsulated into a WebSocket extended frame. When the data transmission mode is high-speed transmission mode and the task priority identifier is high priority, the high-speed transmission mode and the task priority identifier are encapsulated into a WebSocket extended frame; When the data transmission mode is high-speed transmission mode and the task priority identifier is low priority, the high-speed transmission mode is converted to super throughput mode. The super throughput pattern and the task priority identifier are encapsulated into a WebSocket extended frame; The WebSocket extended frame is used as the front-end and back-end communication protocol.
[0010] Optionally, the historical performance data of the monitored WebSocket communication link within a continuous time window includes: Monitor the transmission latency, packet loss rate, and frame length of the WebSocket communication link within each time window of a continuous time window; The transmission delay, packet loss rate, and frame length are used as historical performance data.
[0011] Optionally, combining the transmission delay and the packet loss rate into a two-dimensional feature matrix includes: A smoothed transmission delay is obtained by applying a moving average filter to the transmission delay within each time window. The smooth transmission delay and packet loss rate within each time window are combined into a two-dimensional feature vector; Using each two-dimensional feature vector as a matrix row, the two-dimensional feature vectors within a continuous time window are combined into a two-dimensional feature matrix.
[0012] Optionally, the step of outputting the network state label corresponding to the two-dimensional feature matrix through the density clustering model includes: The density clustering model outputs the label of each row of data in the two-dimensional feature matrix; The labels of each row of matrix data are combined into a label array, and the label array is used as the network state label.
[0013] Optionally, before outputting the label of each row of data in the two-dimensional feature matrix through the density clustering model, the method further includes: Based on the distance between any two rows of data in a matrix, determine whether any two rows of data in a matrix are neighbors using the following method: ; in, This indicates that there is a neighbor relationship between any two rows of data in the matrix. This indicates that no two rows of data in the matrix are neighbors. Indicates other, This represents the distance between any two rows of data in the matrix. This represents the delay difference between every two rows of data in the matrix. This represents the denormalized delay error. This represents the difference in packet loss rate between every two rows of data in the matrix. This represents the inverse normalized packet loss rate error. Represents the neighborhood radius.
[0014] Optionally, extracting the task priority identifier from the data packet includes: Extract metadata from the data packet; Extract the task priority identifier from the metadata.
[0015] Compared to the problems described in the background technology, this invention provides a data foundation for subsequent pattern recognition by collecting historical data within a continuous time window. This makes network state judgment no longer reactive but based on historical trend analysis, thus breaking through the limitations of traditional methods that rely solely on real-time instantaneous indicators. This invention automatically clusters different network state patterns from historical data through unsupervised learning, making the recognition results more scientific and adaptable to complex and ever-changing real-world network environments, possessing predictive capabilities. This invention achieves refined and differentiated strategies by triggering distinctly different transmission patterns based on different identified label patterns, directly improving transmission efficiency and reliability. This invention introduces AI task priorities, breaking the limitations of traditional network optimization that only focuses on network layer indicators. It considers the different communication quality requirements of different tasks in AI applications. This invention integrates objective network conditions with subjective business needs to generate the final communication protocol, solving the fundamental problem of failing to meet the personalized communication quality requirements of AI applications, achieving optimal allocation of network resources and maximizing user experience. Therefore, this invention can improve the reliability of adaptive control of WebSocket communication in AI application scenarios. Attached Figure Description
[0016] Figure 1 This is a flowchart illustrating a method for implementing a front-end and back-end communication protocol for an AI application based on WebSocket, according to an embodiment of the present invention. Figure 2 A network classification diagram illustrating a WebSocket-based AI application front-end and back-end communication protocol implementation method according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the modules implementing the WebSocket-based AI application front-end and back-end communication protocol implementation system according to an embodiment of the present invention.
[0017] The objectives, features, and advantages of this invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0018] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0019] This application provides a method for implementing a front-end and back-end communication protocol for AI applications based on WebSocket. The execution entity of this WebSocket-based AI application front-end and back-end communication protocol implementation method includes, but is not limited to, at least one of the following electronic devices that can be configured to execute the method provided in this application embodiment: a server, a terminal, etc. In other words, the WebSocket-based AI application front-end and back-end communication protocol implementation method can be executed by software or hardware installed on a terminal device or a server device. The server includes, but is not limited to, a single server, a server cluster, a cloud server, or a cloud server cluster.
[0020] Reference Figure 1 The diagram shown is a flowchart illustrating a method for implementing a WebSocket-based AI application front-end and back-end communication protocol according to an embodiment of the present invention. In this embodiment, the WebSocket-based AI application front-end and back-end communication protocol implementation method includes: S1. Monitor the historical performance data of the WebSocket communication link within a continuous time window, wherein the historical performance data includes transmission delay, packet loss rate and frame length.
[0021] This invention provides a data foundation for subsequent pattern recognition by collecting historical data within a continuous time window, making network state judgment no longer reactive but based on historical trend analysis, thus breaking through the limitations of traditional methods that rely solely on real-time instantaneous indicators.
[0022] In one embodiment of the present invention, the monitoring of historical performance data of the WebSocket communication link within a continuous time window includes: monitoring the transmission delay, packet loss rate, and frame length of the WebSocket communication link within each time window of the continuous time window; and using the transmission delay, packet loss rate, and frame length as historical performance data.
[0023] The WebSocket communication link refers to a full-duplex TCP connection channel established based on RFC6455 between the AI application front-end and the AI back-end server, used for real-time bidirectional data frame transmission. The continuous time window refers to several equal-length intervals obtained by dividing a continuous time segment into non-overlapping intervals with a fixed step size. Each interval is called a time window. The time window refers to a fixed-length time period in which performance data is collected as a sample. The transmission delay refers to the time elapsed from when the data frame leaves the sending WebSocket library running in the front-end to when it fully arrives at the receiving WebSocket library running in the back-end within a time window, taken as the average value within the window. The packet loss rate refers to the percentage of data frames that have not been received by the ACK end within a time window out of the total number of data frames sent. The frame length refers to the byte length of each WebSocket data frame within a time window, which can be recorded as the average frame length for subsequent splitting and merging strategies.
[0024] S2. Combine the transmission delay and the packet loss rate into a two-dimensional feature matrix, and input the two-dimensional feature matrix into a density clustering model to output the network state label corresponding to the two-dimensional feature matrix through the density clustering model.
[0025] The embodiments of the present invention automatically cluster different network state patterns from historical data through unsupervised learning, making the recognition results more scientific and more adaptable to complex and ever-changing real network environments, and possessing predictive capabilities.
[0026] In one embodiment of the present invention, the step of combining the transmission delay and the packet loss rate into a two-dimensional feature matrix includes: performing a moving average filter on the transmission delay within each time window to obtain a smoothed transmission delay; combining the smoothed transmission delay and the packet loss rate within each time window into a two-dimensional feature vector; and using each two-dimensional feature vector as matrix row data, combining the two-dimensional feature vectors within consecutive time windows into a two-dimensional feature matrix.
[0027] In one embodiment of the present invention, before outputting the network state label corresponding to the two-dimensional feature matrix through the density clustering model, the method further includes: collecting parameter tuning samples on the WebSocket communication link, wherein the parameter tuning samples include historical latency and historical packet loss rate; normalizing the historical latency and the historical packet loss rate respectively to obtain normalized latency and normalized packet loss rate; determining the sample point corresponding to each pair of normalized latency and normalized packet loss rate; calculating the fourth nearest neighbor distance of each sample point based on the k-distance method; and performing k-distance k-distance k-nearest neighbor ... Sort the rows from smallest to largest to generate the k-distance curve of the fourth nearest neighbor distance; find the inflection point of the curve from the k-distance curve; use the normalized distance value corresponding to the inflection point to inversely deduce the neighborhood radius of the density clustering model; set the spatial neighbor number threshold of the density clustering model; calculate the silhouette coefficient and noise rate of each spatial neighbor number threshold according to the density clustering model; determine the minimum number of neighbors of the density clustering model based on the silhouette coefficient and the noise rate; deploy the neighborhood radius and the minimum number of neighbors to the density clustering model.
[0028] The parameter tuning samples refer to all historical performance records collected from the WebSocket communication link during the offline phase before the density clustering model is officially launched. Each record contains a pair of historical delay and historical packet loss rate. The historical delay refers to the transmission delay time series value recorded in the above samples, and the historical packet loss rate refers to the packet loss percentage sequence value recorded in the above samples. The normalized delay refers to the dimensionless value mapped to the interval [0, 1] after normalizing the historical delay using Min-Max or Z-Score. The normalized packet loss rate refers to the historical packet loss rate mapped to the interval [0, 1] using the same normalization method. 1] The dimensionless value of the interval, the sample point refers to a discrete point plotted in a two-dimensional coordinate system with normalized delay as the abscissa and normalized packet loss rate as the ordinate. Each point corresponds to a network quality feature of a time window. The fourth nearest neighbor distance refers to the Euclidean distance from each sample point to its fourth nearest sample point, used for plotting the k-distance curve. The k-distance curve is a monotonically increasing curve formed by sorting the fourth nearest neighbor distances of all sample points from smallest to largest. The abscissa is the index of each distance, and the ordinate is each distance. The inflection point of the curve refers to the position where the slope of the k-distance curve increases significantly. The neighborhood radius refers to the threshold distance derived from the normalized distance of the curve inflection point to the original dimension. The spatial neighbor number threshold refers to the candidate set {3, 5, 7}, etc., used to compare the silhouette coefficient and noise rate during the optimization stage to finally determine the value of the minimum number of neighbors. The silhouette coefficient is a dimensionless index for evaluating cluster compactness and separation, with a value of [-1, ... [1] The larger the value, the better the clustering effect. It should be noted that the DBSCAN implementation of sklearn is called from sklearn.cluster import DBSCAN, labels = DBSCAN(...).fit_predict(X). DBSCAN is the density clustering model. Then, the Silhouette implementation of sklearn is used from sklearn.metricsim import silhouette_score, score = silhouette_score(X, labels). Here, score is the silhouette coefficient. The noise rate refers to the proportion of sample points marked as noise (labeled as -1) by DBSCAN out of all sample points. The minimum number of neighbors refers to the final hyperparameter selected after weighing the silhouette coefficient and the noise rate, which represents the minimum number of neighbors required for a core point.
[0029] As another embodiment, the step of using the normalized distance value corresponding to the inflection point of the curve to inversely deduce the neighborhood radius of the density clustering model includes: calculating the neighborhood radius of the density clustering model using the following formula based on the normalized distance value corresponding to the inflection point of the curve: ; ; ; ; in, Represents the neighborhood radius. This represents the dimensionless scaling factor. Indicates the maximum range of delay values. This represents the minimum range of delay values. This represents the denormalized delay error. This represents the maximum range of packet loss rate. This represents the minimum range of packet loss rate. This represents the inverse normalized packet loss rate error. Represents the normalized distance value. The standard deviation representing historical lag The standard deviation of the historical packet loss rate.
[0030] The neighborhood radius refers to the final threshold, which is directly used in DBSCAN. As a standard and The scaling factor, that is... Inside, because the normalization is unknown... Normalization The specific value, therefore, will be normalized. Approximately equal to Normalization Also approximately equal to This is actually a normalization process. The normalized values were evenly distributed. Normalization This also ensures subsequent After denormalization Fluctuating around the square of, It is the ordinate of the inflection point, but at this point... It is dimensionless, meaning it's the normalized fourth nearest neighbor distance. , , , It is determined by the upper and lower limits of the statistical training samples. In general, It is the original value, in its inverse normalized form, and... It is the normalized form.
[0031] In one embodiment of the present invention, the step of outputting the network state label corresponding to the two-dimensional feature matrix through the density clustering model includes: outputting the label of each matrix row data in the two-dimensional feature matrix through the density clustering model; combining the labels of each matrix row data into a label array, and using the label array as the network state label.
[0032] The density clustering model is a commonly used unsupervised clustering algorithm in the industry. It divides samples into clusters based on the density reachability of sample points in the feature space. For any sample set to be clustered, the input is the neighborhood radius and the minimum number of neighbors min_samples, and the output is the cluster label and noise label. If the number of neighbors of a sample point in its neighborhood radius is not less than min_samples, then the point is a core point. All samples that are density reachable from the core point are grouped into the same cluster, and the remaining samples are labeled as noise. The labels of each matrix row are as follows: Mode 1 (label 0): {low latency, low packet loss rate}, which is a good network area; Mode 2 (label 1): {high latency, high packet loss rate}, which is a congested network area; Mode 3 (label 2): {high latency, low packet loss rate}, which is a high latency network area; Mode 4 (label -1): noise. Therefore, the network state label is a simple sequence of numerical labels (-1, 0, 1, 2, ...), which is an identifier of the network state pattern.
[0033] See Figure 2 The diagram shown illustrates network classification for a WebSocket-based AI application front-end and back-end communication protocol implementation method according to an embodiment of the present invention. Figure 2 In the subsequent transmission, the high-latency network areas and high-packet-loss networks that exist can remain as they are, that is, the regular WebSocket protocol frames. They do not need to be split or merged, and no additional operations are required. They are simply assembled into regular WebSocket protocol frames.
[0034] As another embodiment, before outputting the label of each row of data in the two-dimensional feature matrix through the density clustering model, the method further includes: determining whether two rows of data are neighbors based on the distance between them using the following method: ; in, This indicates that there is a neighbor relationship between any two rows of data in the matrix. This indicates that no two rows of data in the matrix are neighbors. Indicates other, This represents the distance between any two rows of data in the matrix. This represents the delay difference between every two rows of data in the matrix. This represents the denormalized delay error. This represents the difference in packet loss rate between every two rows of data in the matrix. This represents the inverse normalized packet loss rate error. Represents the neighborhood radius.
[0035] S3. Based on the frame length and the network status label, determine the data transmission mode of the WebSocket communication link.
[0036] This invention, by no longer using a single adjustment strategy but triggering drastically different transmission patterns based on different identified tag patterns, achieves refined and differentiated strategies, directly improving transmission efficiency and reliability.
[0037] In one embodiment of the present invention, determining the data transmission mode of the WebSocket communication link based on the frame length and the network status label includes: when the label in the network status label is a high-latency, high-packet-loss mode, triggering an anti-interference transmission mode of the WebSocket communication link based on the frame length, wherein the anti-interference transmission mode refers to splitting data packets into multiple subframes no larger than the maximum transmission unit and adding redundant check information to each subframe; when the label in the network status label is a low-latency, low-packet-loss mode, triggering a high-speed transmission mode of the WebSocket communication link based on the frame length, wherein the high-speed transmission mode refers to merging data packets into long frames no larger than the maximum transmission unit; and using the anti-interference transmission mode and the high-speed transmission mode as the data transmission mode.
[0038] The anti-interference transmission mode refers to the transmission strategy triggered under high latency and high packet loss mode. It mainly includes splitting the data packet to be sent into multiple subframes, as long as the length of each subframe is not greater than the maximum transmission unit (MTU) (random splitting or fixed interval splitting are also acceptable, as long as it is not greater than the MTU). Redundancy check information is added to each subframe to improve reliability. The maximum transmission unit (MTU) is the maximum number of bytes allowed per packet in the network path, which is 1500 bytes in common Ethernet paths. The subframe refers to a small frame with a length not exceeding the MTU, which is split from the original data packet under the anti-interference mode. The redundancy check information refers to the check field attached to the end of the subframe, which is used by the receiving end to detect and recover errors. The high-speed transmission mode refers to the transmission strategy triggered under low latency and low packet loss mode. It mainly includes merging multiple data packets into a long frame, with the length of the merged frame not greater than the MTU. Throughput is improved by reducing or canceling redundancy check. The data transmission mode refers to the strategy set composed of the anti-interference transmission mode and the high-speed transmission mode, which is used to guide the real-time encapsulation and scheduling of WebSocket frames.
[0039] S4. Receive data packets sent from the AI application front-end in the WebSocket communication management module of the AI supply backend, and extract the task priority identifier from the data packets.
[0040] This invention introduces AI task prioritization, breaking the limitation of traditional network optimization that only focuses on network layer indicators, and can take into account the different communication quality requirements of different tasks in AI applications.
[0041] In one embodiment of the present invention, extracting the task priority identifier from the data packet includes: extracting metadata from the data packet; and extracting the task priority identifier from the metadata.
[0042] The data packet refers to a data unit transmitted in network communication, such as an AI request processing packet. The metadata refers to data about the data, which describes the structure, content, processing method, and other information of the data packet. The task priority identifier refers to information contained in the metadata that indicates the importance or urgency of the task carried by the data packet.
[0043] S5. Based on the task priority identifier, generate the front-end and back-end communication protocol of the data packet using the data transmission format.
[0044] This invention integrates the objective state of the network with the subjective needs of the business to generate the final communication protocol. This solves the fundamental problem of the difficulty in meeting the personalized communication quality requirements of AI applications, and achieves the optimal allocation of network resources and the maximization of user experience.
[0045] In one embodiment of the present invention, the step of generating the front-end and back-end communication protocol of the data packet using the data transmission mode based on the task priority identifier includes: when the data transmission mode is an anti-interference transmission mode and the task priority identifier is high priority, converting the anti-interference transmission mode into a super anti-interference mode; encapsulating the super anti-interference mode and the task priority identifier into a WebSocket extended frame, wherein the WebSocket extended frame includes frame mode, maximum frame length, subframe length, redundancy level, retransmission timeout flag, priority coverage flag, and application layer load; when the data transmission mode is an anti-interference transmission mode and the task priority identifier is low priority, encapsulating the anti-interference transmission mode and the task priority identifier into a WebSocket extended frame; when the data transmission mode is a high-speed transmission mode and the task priority identifier is high priority, encapsulating the high-speed transmission mode and the task priority identifier into a WebSocket extended frame; when the data transmission mode is a high-speed transmission mode and the task priority identifier is low priority, converting the high-speed transmission mode into a super throughput mode; encapsulating the super throughput mode and the task priority identifier into a WebSocket extended frame; and using the WebSocket extended frame as the front-end and back-end communication protocol.
[0046] The super anti-interference mode refers to further strengthening the original anti-interference transmission mode, including smaller subframes and more redundancy. Specifically, the subframe size is further reduced to no more than 50% of the path MTU. For example, for an Ethernet MTU (1500 bytes), the subframe size does not exceed 750 bytes. Redundancy check information is added, with double redundancy added to each subframe to improve the reliability of data transmission. The super throughput mode refers to a more aggressive approach to the original high-speed strategy, namely, merging more packets. Specifically, more data packets are merged, so that the length of the merged frame reaches 90% of the path MTU. For example, for an Ethernet MTU (1500 bytes), the length of the merged frame exceeds 1350 bytes but does not exceed 1500 bytes. Redundancy check overhead is reduced by adding lightweight check information only to the merged frame to reduce additional transmission burden.
[0047] For example, the frame mode FrameMode is {0=merge frames, 1=split frames}, the maximum frame length MaxFrameSize is the maximum frame length (bytes, not greater than MTU), the subframe length SubFrameSize is the length of the split subframes, the redundancy level RedundancyLevel is {0=off, 1=single redundancy, 2=double redundancy}, the retransmission timeout flag is RetxTimeout, the priority override flag is PriorityOverride, and PriorityOverride indicates whether to enforce a conservative strategy {0=no, 1=yes}. The application layer load is the data packet mentioned above.
[0048] Furthermore, to better understand the front-end and back-end communication protocols in the above-described method for implementing the front-end and back-end communication protocols of the WebSocket-based AI application, please refer to Table 1 below, which is a table of front-end and back-end communication protocols in an embodiment of the present invention for implementing the WebSocket-based AI application front-end and back-end communication protocols.
[0049] Table 1 Front-end and Back-end Communication Protocol Table ; As can be clearly seen from Table 1 above, in the implementation method of the front-end and back-end communication protocol of AI applications based on WebSocket, the objective network status and the subjective business needs can be integrated to generate the final communication protocol. This solves the fundamental problem of not being able to meet the personalized needs of AI applications for communication quality, and realizes the optimal allocation of network resources and the maximization of user experience.
[0050] Compared to the problems described in the background technology, this invention provides a data foundation for subsequent pattern recognition by collecting historical data within a continuous time window. This makes network state judgment no longer reactive but based on historical trend analysis, thus breaking through the limitations of traditional methods that rely solely on real-time instantaneous indicators. This invention automatically clusters different network state patterns from historical data through unsupervised learning, making the recognition results more scientific and adaptable to complex and ever-changing real-world network environments, possessing predictive capabilities. This invention achieves refined and differentiated strategies by triggering distinctly different transmission patterns based on different identified label patterns, directly improving transmission efficiency and reliability. This invention introduces AI task priorities, breaking the limitations of traditional network optimization that only focuses on network layer indicators. It considers the different communication quality requirements of different tasks in AI applications. This invention integrates objective network conditions with subjective business needs to generate the final communication protocol, solving the fundamental problem of failing to meet the personalized communication quality requirements of AI applications, achieving optimal allocation of network resources and maximizing user experience. Therefore, this invention can improve the reliability of adaptive control of WebSocket communication in AI application scenarios.
[0051] like Figure 3 The diagram shown is a functional block diagram of a WebSocket-based AI application front-end and back-end communication protocol implementation system according to the present invention.
[0052] The WebSocket-based AI application front-end and back-end communication protocol implementation system 300 described in this invention can be installed in an electronic device. Depending on the functions implemented, the WebSocket-based AI application front-end and back-end communication protocol implementation system may include a data monitoring module 301, a tag output module 302, a morphology determination module 303, an identifier extraction module 304, and a protocol generation module 305. The module described in this invention can also be called a unit, which refers to a series of computer program segments that can be executed by the processor of an electronic device and can perform a fixed function, stored in the memory of the electronic device.
[0053] In this embodiment of the invention, the functions of each module / unit are as follows: The data monitoring module 301 is used to monitor the historical performance data of the WebSocket communication link within a continuous time window, wherein the historical performance data includes transmission delay, packet loss rate and frame length. The tag output module 302 is used to combine the transmission delay and the packet loss rate into a two-dimensional feature matrix, and input the two-dimensional feature matrix into a density clustering model, so as to output the network state label corresponding to the two-dimensional feature matrix through the density clustering model; The morphology determination module 303 is used to determine the data transmission morphology of the WebSocket communication link based on the frame length and the network status label; The identifier extraction module 304 is used to receive data packets sent from the AI application front end in the WebSocket communication management module of the AI supply backend, and extract the task priority identifier from the data packets. The protocol generation module 305 is used to generate the front-end and back-end communication protocol of the data packet based on the task priority identifier and the data transmission format.
[0054] In detail, the modules in the WebSocket-based AI application front-end and back-end communication protocol implementation system 300 described in this embodiment of the invention adopt the same approach as described above. Figure 1 The method used is the same as the front-end and back-end communication protocol implementation method for AI applications based on WebSocket described in the article, and can produce the same technical effect, so it will not be repeated here.
[0055] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.
[0056] Finally, it should be noted that in the above embodiments, each embodiment can be combined with each other or independent. Deleting any one of them will not affect the technical implementation of other embodiments. The above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. A method for implementing a front-end and back-end communication protocol for AI applications based on WebSocket, characterized in that, The method includes: Monitor historical performance data of the WebSocket communication link within a continuous time window, wherein the historical performance data includes transmission delay, packet loss rate, and frame length; The transmission delay and the packet loss rate are combined into a two-dimensional feature matrix, and the two-dimensional feature matrix is input into a density clustering model so that the network state label corresponding to the two-dimensional feature matrix is output through the density clustering model. Based on the frame length and the network status label, the data transmission pattern of the WebSocket communication link is determined; The WebSocket communication management module in the AI supply backend receives data packets sent from the AI application frontend and extracts the task priority identifier from the data packets. Based on the task priority identifier, the front-end and back-end communication protocol for generating the data packet is generated using the data transmission format.
2. The method for implementing the front-end and back-end communication protocol of AI applications based on WebSocket as described in claim 1, characterized in that, Before outputting the network state labels corresponding to the two-dimensional feature matrix through the density clustering model, the method further includes: Collect parameter tuning samples on the WebSocket communication link, wherein the parameter tuning samples include historical latency and historical packet loss rate; The historical latency and the historical packet loss rate are normalized respectively to obtain normalized latency and normalized packet loss rate; Determine the sample points corresponding to each pair of normalized delay and normalized packet loss rate; The fourth nearest neighbor distance for each sample point is calculated using the k-distance method. Sort the fourth nearest neighbor distances from smallest to largest to generate the k-distance curve of the fourth nearest neighbor distance; Find the inflection point of the k-distance curve; The neighborhood radius of the density clustering model is inversely calculated using the normalized distance value corresponding to the inflection point of the curve. Set a threshold for the number of spatial neighbors in the density clustering model; Based on the density clustering model, calculate the silhouette coefficient and noise rate for each spatial neighbor number threshold; Based on the silhouette coefficient and the noise rate, the minimum number of neighbors for the density clustering model is determined; The neighborhood radius and the minimum number of neighbors are deployed into the density clustering model.
3. The method for implementing the front-end and back-end communication protocol of AI applications based on WebSocket as described in claim 2, characterized in that, The step of using the normalized distance value corresponding to the inflection point of the curve to inversely deduce the neighborhood radius of the density clustering model includes: Based on the normalized distance value corresponding to the inflection point of the curve, the neighborhood radius of the density clustering model is calculated using the following formula: ; ; ; ; in, Represents the neighborhood radius. This represents the dimensionless scaling factor. Indicates the maximum range of delay values. This represents the minimum range of delay values. This represents the denormalized delay error. This represents the maximum range of packet loss rate. This represents the minimum range of packet loss rate. This represents the inverse normalized packet loss rate error. Represents the normalized distance value. The standard deviation representing historical lag The standard deviation of the historical packet loss rate.
4. The method for implementing the front-end and back-end communication protocol of AI applications based on WebSocket as described in claim 1, characterized in that, Determining the data transmission pattern of the WebSocket communication link based on the frame length and the network status label includes: When the label in the network status label is high latency and high packet loss mode, based on the frame length, the anti-interference transmission mode of the WebSocket communication link is triggered. The anti-interference transmission mode refers to the mode of splitting the data packet into multiple subframes no larger than the maximum transmission unit and adding redundant check information to each subframe. When the label in the network status label is low latency and low packet loss mode, the high-speed transmission mode of the WebSocket communication link is triggered based on the frame length. The high-speed transmission mode refers to the mode of merging data packets into long frames no larger than the maximum transmission unit. The anti-interference transmission mode and the high-speed transmission mode are used as data transmission modes.
5. The method for implementing the front-end and back-end communication protocol of AI applications based on WebSocket as described in claim 1, characterized in that, The step of generating the data packet using the data transmission format based on the task priority identifier includes: When the data transmission mode is anti-interference transmission mode and the task priority identifier is high priority, the anti-interference transmission mode is converted to super anti-interference mode. The super anti-interference mode and the task priority identifier are encapsulated into a WebSocket extended frame, wherein the WebSocket extended frame includes frame mode, maximum frame length, subframe length, redundancy level, retransmission timeout flag, priority overlay flag and application layer load. When the data transmission mode is an anti-interference transmission mode and the task priority identifier is a low priority, the anti-interference transmission mode and the task priority identifier are encapsulated into a WebSocket extended frame. When the data transmission mode is high-speed transmission mode and the task priority identifier is high priority, the high-speed transmission mode and the task priority identifier are encapsulated into a WebSocket extended frame; When the data transmission mode is high-speed transmission mode and the task priority identifier is low priority, the high-speed transmission mode is converted to super throughput mode. The super throughput pattern and the task priority identifier are encapsulated into a WebSocket extended frame; The WebSocket extended frame is used as the front-end and back-end communication protocol.
6. The method for implementing the front-end and back-end communication protocol of AI applications based on WebSocket as described in claim 1, characterized in that, The historical performance data of the monitored WebSocket communication link within a continuous time window includes: Monitor the transmission latency, packet loss rate, and frame length of the WebSocket communication link within each time window of a continuous time window; The transmission delay, packet loss rate, and frame length are used as historical performance data.
7. The method for implementing the front-end and back-end communication protocol of AI applications based on WebSocket as described in claim 1, characterized in that, The step of combining the transmission delay and the packet loss rate into a two-dimensional feature matrix includes: A smoothed transmission delay is obtained by applying a moving average filter to the transmission delay within each time window. The smooth transmission delay and packet loss rate within each time window are combined into a two-dimensional feature vector; Using each two-dimensional feature vector as a matrix row, the two-dimensional feature vectors within a continuous time window are combined into a two-dimensional feature matrix.
8. The method for implementing the front-end and back-end communication protocol of AI applications based on WebSocket as described in claim 1, characterized in that, The step of outputting the network state label corresponding to the two-dimensional feature matrix through the density clustering model includes: The density clustering model outputs the label of each row of data in the two-dimensional feature matrix; The labels of each row of matrix data are combined into a label array, and the label array is used as the network state label.
9. The method for implementing the front-end and back-end communication protocol of AI applications based on WebSocket as described in claim 8, characterized in that, Before outputting the label of each row of data in the two-dimensional feature matrix through the density clustering model, the method further includes: Based on the distance between any two rows of data in a matrix, determine whether any two rows of data in a matrix are neighbors using the following method: ; in, This indicates that there is a neighbor relationship between any two rows of data in the matrix. This indicates that no two rows of data in the matrix are neighbors. Indicates other, This represents the distance between any two rows of data in the matrix. This represents the delay difference between every two rows of data in the matrix. This represents the denormalized delay error. This represents the difference in packet loss rate between every two rows of data in the matrix. This represents the inverse normalized packet loss rate error. Represents the neighborhood radius.
10. The method for implementing the front-end and back-end communication protocol of AI applications based on WebSocket as described in claim 1, characterized in that, Extracting the task priority identifier from the data packet includes: Extract metadata from the data packet; extract task priority identifier from the metadata.