Long connection communication method and system based on Netty framework and medium

By using WebSocket long connection communication method in the Netty framework, the problem of large resource overhead and delay in HTTP short connection communication mode is solved, and stable and efficient real-time communication between the client and the server is realized, and the message delivery is reliable, and it is also implemented on the network The disconnection and reconnection are performed in the event of a failure, meeting the real-time communication needs.

CN119183211APending Publication Date: 2024-12-24SHENZHEN LEXIN SOFTWARE TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411256761.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-09
Publication Date
2024-12-24

AI Technical Summary

Technical Problem

The existing HTTP short-connect communication method requires frequent establishment and disconnection when the client communicates with the server, resulting in large resource overhead and delay, and real-time communication cannot be achieved, especially in scenarios where real-time communication is required.

Method used

The WebSocket long connection communication method based on the Netty framework is adopted to establish a long connection between the client and the server, and a long connection gateway and push routing server are used to achieve stable and efficient real-time communication, and disconnect and reconnect in the event of network failure.

Benefits of technology

It realizes stable and efficient real-time communication between the client and the server, ensures reliable delivery of messages, and promptly disconnects and reconnects in the event of network failure, improving the robustness of the system and business continuity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119183211A_ABST
    Figure CN119183211A_ABST
Patent Text Reader

Abstract

The invention discloses a long connection communication method and system based on a Netty framework and a medium, and the method comprises the steps: after a server establishes a WebSocket long connection based on the Netty framework with a client, if a communication request is detected, sending a current message to the client; the client sends a current confirmation message to the server; if the server receives the current acknowledgement message and the receiving duration is not overtime, the current acknowledgement message is stored; and if the server receives the current acknowledgement message and the receiving duration is overtime or the current acknowledgement message is not received, the server retransmits the current message to the client based on the message retransmission strategy. According to the embodiment of the invention, WebSocket long connection can be realized based on the long connection gateway and the push routing server in the Netty framework, stable and efficient real-time communication between the server and the client can be ensured, reliable delivery of messages can be ensured, and timely disconnection and reconnection can be carried out when a network fault occurs between the server and the client.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer communication technology, and in particular to a long connection communication method, system and medium based on a Netty framework. Background Art

[0002] Currently, HTTP (full name is Hypertext Transfer Protocol) short connection communication method is often used between clients and servers. Every time the client communicates with the server, it needs to establish and disconnect the connection, which will cause large resource overhead and delay. Moreover, when the client is disconnected from the server, it is impossible to automatically reconnect and continue the previous message after the network is disconnected. In some scenarios that require real-time communication, such as Bluetooth printing, chatting, etc., HTTP short connection communication method cannot meet the needs. Summary of the invention

[0003] The embodiments of the present invention provide a long connection communication method, system and medium based on the Netty framework, aiming to solve the problem that when the HTTP short connection communication mode is adopted in the scene requiring real-time communication in the prior art, the client needs to establish and disconnect the connection each time it communicates with the server, which will cause large resource overhead and delay.

[0004] In a first aspect, an embodiment of the present invention provides a long connection communication method based on a Netty framework, which is applied to a long connection communication system based on a Netty framework, wherein the long connection communication system based on the Netty framework includes a client and a server, and the Netty framework carried in the server includes at least a long connection gateway and a push routing server; the long connection communication method based on the Netty framework includes:

[0005] The client establishes a WebSocket persistent connection based on the Netty framework with the persistent connection gateway in the server;

[0006] If the server detects a communication request, the server sends a current message corresponding to the communication request to the client;

[0007] If the client receives the current message, it generates a current confirmation message corresponding to the current message and sends it to the server;

[0008] If the persistent connection gateway in the server receives the current confirmation message and determines that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, the push routing server in the server saves the current confirmation message;

[0009] If the persistent connection gateway in the server receives the current confirmation message and determines that the interval between the reception time of the current confirmation message and the sending time of the current message exceeds the preset detection time, or the persistent connection gateway in the server does not receive the current confirmation message, the current message is retransmitted to the client based on the preset message retransmission strategy.

[0010] In a second aspect, an embodiment of the present invention further provides a persistent connection communication system based on a Netty framework, which includes a client and a server, wherein the Netty framework carried in the server includes at least a persistent connection gateway and a push routing server;

[0011] The client is used to establish a WebSocket persistent connection based on the Netty framework with the persistent connection gateway in the server;

[0012] The server is configured to send a current message corresponding to the communication request to the client if a communication request is detected;

[0013] The client is further configured to generate a current confirmation message corresponding to the current message and send the message to the server if the current message is received;

[0014] The persistent connection gateway in the server is configured to, if the current confirmation message is received and it is determined that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed a preset detection time, store the current confirmation message in the push routing server in the server;

[0015] The persistent connection gateway in the server is also used to retransmit the current message to the client based on a preset message retransmission strategy if the current confirmation message is received and it is determined that the interval between the reception time of the current confirmation message and the sending time of the current message exceeds a preset detection time length, or the persistent connection gateway in the server does not receive the current confirmation message.

[0016] In a third aspect, an embodiment of the present invention further provides a long connection communication system based on a Netty framework, which includes at least two computer devices, each of which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processors in at least two of the computer devices execute the corresponding computer program, they jointly implement the method described in the first aspect above.

[0017] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the method described in the first aspect above can be implemented.

[0018] The embodiment of the present invention provides a long connection communication method, system and medium based on the Netty framework, and the method includes: a client and a server establish a WebSocket long connection based on the Netty framework; if the server detects a communication request, the current message corresponding to the communication request is sent to the client; if the client receives the current message, the current confirmation message corresponding to the current message is generated and sent to the server; if the server receives the current confirmation message and determines that the interval between the receiving time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, the current confirmation message is saved; if the server receives the current confirmation message and determines that the interval between the receiving time of the current confirmation message and the sending time of the current message exceeds the preset detection time, or the server does not receive the current confirmation message, the current message is retransmitted to the client based on the preset message retransmission strategy. The embodiment of the present invention can realize the WebSocket long connection based on the long connection gateway and push routing server in the Netty framework to ensure stable and efficient real-time communication between the server and the client, and can also ensure the reliable delivery of messages, and timely disconnection and reconnection when a network failure occurs between the server and the client. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.

[0020] Figure 1 A schematic diagram of an application scenario of a long connection communication method based on a Netty framework provided in an embodiment of the present invention;

[0021] Figure 2 A schematic diagram of a long connection communication method based on the Netty framework provided in an embodiment of the present invention;

[0022] Figure 3 A schematic diagram of a sub-process of a long connection communication method based on a Netty framework provided in an embodiment of the present invention;

[0023] Figure 4 A schematic diagram of the structure of the Netty framework carried by the server in the long connection communication method based on the Netty framework provided in an embodiment of the present invention;

[0024] Figure 5 A schematic diagram of a sub-process of a long connection communication method based on a Netty framework provided in an embodiment of the present invention;

[0025] Figure 6A schematic diagram of a sub-process of a long connection communication method based on a Netty framework provided in an embodiment of the present invention;

[0026] Figure 7 A schematic diagram of a sub-process of a long connection communication method based on a Netty framework provided in an embodiment of the present invention;

[0027] Figure 8 A schematic block diagram of a long connection communication system based on the Netty framework provided in an embodiment of the present invention;

[0028] Fig. 9 A schematic block diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0029] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0030] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0031] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0032] It should be further understood that the term "and / or" used in the present description and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0033] Please also refer to Figure 1 , Figure 2 and Figure 4 ,in Figure 1 The following is a schematic diagram of a long connection communication method based on the Netty framework according to an embodiment of the present invention. Figure 2 is a flow chart of a long connection communication method based on the Netty framework provided in an embodiment of the present invention. Figure 4Schematic diagram of the Netty framework structure carried by the server in the long connection communication method based on the Netty framework provided in the embodiment of the present invention. Figure 1 and Figure 4 As shown, the long connection communication method based on the Netty framework provided in an embodiment of the present invention is applied to a long connection communication system based on the Netty framework. The long connection communication system based on the Netty framework includes a client 10 and a server 20. The Netty framework carried by the server 20 includes at least a long connection gateway 22 and a push routing server 24.

[0034] like Figure 2 As shown, the method includes the following steps S110-S150.

[0035] S110. The client establishes a WebSocket persistent connection based on the Netty framework with the persistent connection gateway in the server.

[0036] In this embodiment, in order to establish a stable long connection communication between the client and the server to maintain real-time communication, a WebSocket long connection based on the Netty framework can be established between the client and the long connection gateway in the server. Netty is a high-performance network programming framework, and the WebSocket protocol allows full-duplex communication on a single TCP (full name is Transmission Control Protocol, indicating the transmission control protocol) connection, which is suitable for application scenarios that require real-time data exchange, such as Bluetooth printing message push and client message notification. Moreover, the Netty framework specifically adopted in this application specifically sets at least a long connection gateway 22 and a push routing server 24. The long connection gateway 22 is the core part of maintaining a long connection between the server and the client, and the push routing server 24 correspondingly shares other processing functions of the long connection gateway 22 other than maintaining a long connection, such as message push routing control.

[0037] In one embodiment, if Figure 3 As shown, step S110 includes:

[0038] S111, the client establishes a WebSocket connection with the persistent connection gateway in the server to obtain a user session corresponding to the client from the platform session control server in the server;

[0039] S112: If the client determines that the user session has passed the verification in the persistent connection gateway, the user channel information corresponding to the client is sent to the Redis server in the server, so that the client establishes a WebSocket persistent connection with the persistent connection gateway.

[0040] In this embodiment, in order to more clearly understand the technical solution of the present application, Figure 1 and Figure 4 The Netty framework installed in the server 20 is introduced. Figure 1 and Figure 4 As shown, when the Netty framework is specifically installed in the server 20, it can be set to at least include a load balancing server 21, a persistent connection gateway 22, a platform session control server 23, a push routing server 24 and a Redis server 25. Afterwards, in combination with the Netty framework structure installed in the server 20, the specific process of establishing a WebSocket persistent connection between the client 10 and the server 20 is as follows:

[0041] 11) An initial WebSocket connection is established between the client 10 and the server 20, specifically, a WebSocket connection is established between the client 10 and the persistent connection gateway 22 in the server 20;

[0042] 12) The persistent connection gateway 22 obtains the user session corresponding to the client 10 from the platform session control server 23;

[0043] 13) The persistent connection gateway 22 verifies the user session, and when the user session passes the verification, the persistent connection gateway 22 obtains the user channel information corresponding to the user session (which can be represented by channel session), and sends it to the Redis server 25;

[0044] 14) The Redis server 25 receives the user channel information and writes it into the local storage space, and sends a notification message of successful writing of the user channel information to the persistent connection gateway 22;

[0045] 15) After receiving the write success notification message, the persistent connection gateway 22 establishes a WebSocket persistent connection with the client 10.

[0046] Among them, the Redis server 25 stores user channel information for different clients. For example, taking the client 10 in the above example as an example, the user channel information stored in the Redis server 25 at least includes a session control ID, a Netty channel ID, server information, and a channel push topic (represented by a channel topic). There are differences between the session control ID, Netty channel ID, server information, and channel push topic included in the user channel information corresponding to different clients. Preferably, each client corresponds to a unique session control ID and Netty channel ID to ensure the uniqueness of the long connection channel between the client and the server. The load balancing server 21 is used to perform load balancing processing when multiple different clients communicate with the server to ensure the availability and stability of the server.

[0047] After completing the WebSocket connection between the two, the client and the server achieve real-time communication. The client can receive communication messages from the server in real time and respond promptly.

[0048] In one embodiment, continue to refer to Figure 3 , after step S112, the following steps are also included:

[0049] S113, the client sends a heartbeat packet to the persistent connection gateway in the server based on a preset heartbeat packet sending period, so that the Redis server in the server updates the renewal information of the user channel information corresponding to the client based on the reception time of the heartbeat packet.

[0050] In this embodiment, reference is still continued simultaneously Figure 1 and Figure 4 In order to maintain the WebSocket persistent connection between the client 10 and the server 20, the client 10 needs to send a heartbeat packet to the server based on a preset heartbeat packet sending cycle. Moreover, each time the server 20 receives a heartbeat packet sent by the client 10, specifically the persistent connection gateway 22 receives the heartbeat packet sent by the client 10, and then the persistent connection gateway 22 sends the heartbeat packet to the Redis server 25 to update the renewal information of the user channel information corresponding to the client 10 in the Redis server 25.

[0051] For example, the user channel information corresponding to the client 10 is stored in the Redis server 25, and the effective time of the long connection in the user channel information is determined by the time when the heartbeat packet sent by the client 10 was received last time. More specifically, the time when the Redis server 25 obtains the heartbeat packet sent by the client 10 last time is recorded as t1, and each time the Redis server 25 detects the time point of receiving the heartbeat packet, it automatically adds the preset effective duration T, such as taking t1+T as the renewal information corresponding to the updated user channel information. That is, in the corresponding time period of [t1, t1+T], the client 10 and the server 20 still maintain a WebSocket long connection. After t1+T is used as the renewal information corresponding to the updated user channel information in the Redis server 25 this time, t1+T is used as the new time when the heartbeat packet sent by the client 10 was received last time, and the renewal information of the user channel information corresponding to the client 10 is continued to be updated with reference to the above example when the heartbeat packet sent by the client 10 is received next time. It can be seen that based on the above-mentioned method of sending heartbeat packets, it is ensured that the client and the server continue to maintain a WebSocket long connection.

[0052] S120: If the server detects a communication request, it sends a current message corresponding to the communication request to the client.

[0053] In this embodiment, the reason why the long connection between the client and the server is ensured is that the server has the need to push messages or send requests to the client in real time. When the server detects or receives a user operation instruction (such as a Bluetooth printing instruction) from the user, it is necessary to promptly send a communication request corresponding to the user operation instruction to the client, specifically, to send the current message corresponding to the communication request to the client. After receiving the current message, the client needs to respond to it in a timely manner.

[0054] In one embodiment, taking the Bluetooth printing message push scenario as an example, the communication request is a Bluetooth printing request, and the current message is a current Bluetooth printing message, such as Figure 5 As shown, step 120 includes:

[0055] S121. If the push routing server detects a Bluetooth print request, acquiring the current Bluetooth print message corresponding to the Bluetooth print request;

[0056] S122, obtaining current server information corresponding to the current Bluetooth printing message in the Redis server;

[0057] S123. If the push routing server determines that the current confirmation message corresponding to the current Bluetooth printing message has not been received, determines that a WebSocket long connection has been established with the client, and determines that the current server information has passed the verification, then obtains the current user channel information from the Redis server;

[0058] S124: The persistent connection gateway updates the current Bluetooth print message based on the current session control ID in the current user channel information, and sends the current Bluetooth print message to the client.

[0059] The current Bluetooth print message includes a current print message ID and a current print message body.

[0060] In this embodiment, continue to refer to Figure 1 and Figure 4 In the Bluetooth printing message push scenario, the client is a printing device with Bluetooth communication function. When the user uses the user terminal to send a Bluetooth printing instruction to the server 20 or the user directly operates the server 20 to generate a Bluetooth printing instruction, the push routing server 24 in the server 20 first obtains the Bluetooth printing request corresponding to the Bluetooth printing instruction, and then obtains the current Bluetooth printing message corresponding to the Bluetooth printing request. The current Bluetooth printing message includes the current printing message ID (the current printing message ID can be directly the user ID corresponding to the client in specific implementation) and the current printing message body (which can be represented by msg).

[0061] Afterwards, the Redis server 25 in the server 20 obtains the current user channel information corresponding to the client 10 and the current Bluetooth print message, and parses and obtains the current server information included therein. The push routing server 24, under the condition that the current confirmation message corresponding to the current Bluetooth print message has not been received, a WebSocket long connection has been established with the client, and the current server information has been verified (wherein the current server information can be verified if it is not a null value), obtains the current user channel information again in full, and obtains the specific data included therein such as the current session control ID, the current Netty channel ID, the current server information, and the current channel push topic, etc. The push routing server 24 can send the current user channel information to the long connection gateway 22.

[0062] Finally, the current session control ID in the current user channel information is first obtained in the persistent connection gateway 22, and the current Bluetooth print message is updated with the current session control ID. Specifically, the current session control ID is added to the current Bluetooth print message, that is, in addition to retaining the current print message ID and the current print message body in the current Bluetooth print message, the current session control ID is also added, thereby obtaining the updated current Bluetooth print message, which is sent from the server to the client. It can be seen that based on the above method, the server can send the current message to the client in a timely manner based on the persistent connection.

[0063] S130: If the client receives the current message, it generates a current confirmation message corresponding to the current message and sends it to the server.

[0064] In this embodiment, under the premise that the client and the server maintain a normal WebSocket long connection, after receiving the current message sent by the server, the client will promptly generate a current confirmation message corresponding to the current message and send it to the server. Among them, the current confirmation message can be understood as a confirmation message (which can be represented by ACK, the full name is Acknowledge character) required in the process of communication between the client and the server. After the client sends the current confirmation message to the server, the server may not be able to successfully receive the current confirmation message. For example, if the long connection between the client and the server is disconnected, the server needs to further confirm whether the current confirmation message is received.

[0065] In one embodiment, if Figure 6 As shown, step S130 includes:

[0066] S131, acquiring a current session control ID in the current Bluetooth print message, and generating the current confirmation message corresponding to the current Bluetooth print message based on the current session control ID;

[0067] S132: Send the current confirmation message to the server.

[0068] In this embodiment, when generating the current confirmation message in the client, it is necessary to first obtain the current session control ID in the current Bluetooth print message, and then add the current session control ID to a preset confirmation message template to obtain the current confirmation message. Afterwards, the client sends the current confirmation message to the server so that the server can further determine whether the current confirmation message is successfully received. Only when the server receives the current confirmation message and determines that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, it means that the client has successfully received the current Bluetooth print message, and the accurate delivery of the message is ensured.

[0069] S140: If the persistent connection gateway in the server receives the current confirmation message and determines that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection duration, the push routing server in the server saves the current confirmation message.

[0070] In this embodiment, if the persistent connection gateway in the server receives the current confirmation message and determines that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, it means that the current Bluetooth print message has been accurately delivered to the client, and the client can then perform corresponding content printing processing based on the current Bluetooth print message. Of course, before the client performs corresponding content printing processing based on the current Bluetooth print message, the current confirmation message can be first saved in the push routing server of the server and a mapping relationship with the current Bluetooth print message can be established.

[0071] In one embodiment, if Figure 7 As shown, step S140 includes:

[0072] S141: If the current confirmation message is received and it is determined that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, obtain the current session control ID in the current confirmation message, and generate a corresponding confirmation message identification value based on the current session control ID;

[0073] S142: Update the confirmation message identification bit value in the current confirmation message based on the confirmation message identification value, and save the updated current confirmation message.

[0074] In this embodiment, when the server specifically confirms in the persistent connection gateway that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, the server can first obtain the current session control ID included in the current confirmation message, and then generate a corresponding confirmation message identification value when it is determined that the current session control ID is not a null value, for example, the confirmation message identification value is represented by SID = 1. Of course, when it is determined that the current session control ID is a null value, a corresponding confirmation message identification value is generated, for example, the confirmation message identification value is represented by SID = 0.

[0075] After obtaining the confirmation message identification value in the persistent connection gateway, the confirmation message identification value can be used to replace the confirmation message identification bit value in the current confirmation message, thereby updating the confirmation message identification bit value in the current confirmation message, and obtaining the updated current confirmation message in the persistent connection gateway. Afterwards, the persistent connection gateway sends the current confirmation message to the push routing server and stores it in the push routing server. It can be seen that through the above method, the server can quickly confirm whether the current confirmation message has been received, and can also ensure reliable transmission of the message based on the current confirmation message.

[0076] S150. If the persistent connection gateway in the server receives the current confirmation message and determines that the interval between the reception time of the current confirmation message and the sending time of the current message exceeds the preset detection time, or the persistent connection gateway in the server does not receive the current confirmation message, the current message is retransmitted to the client based on the preset message retransmission strategy.

[0077] In this embodiment, if the long connection gateway in the server receives the current confirmation message and determines that the interval between the reception time of the current confirmation message and the sending time of the current message exceeds the preset detection time, or the long connection gateway in the server does not receive the current confirmation message, it means that a disconnection has occurred between the server and the client. At this time, the current message can be retransmitted to the client based on the message retransmission strategy. The message retransmission strategy can be regarded as an intelligent disconnection and reconnection mechanism, which ensures that the communication between the server and the client will not be permanently interrupted in an unstable network environment, and supports the continued execution of tasks after disconnection, thereby improving the robustness of the system and ensuring business continuity.

[0078] In one embodiment, step S150 includes:

[0079] The current message is retransmitted to the client based on the message retransmission period in the message retransmission strategy, and retransmitting the current message to the client is stopped when it is detected that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time length, or retransmitting the current message to the client is stopped when it is detected that the cumulative number of times the current message is retransmitted to the client exceeds the preset maximum number of retransmissions.

[0080] In this embodiment, when the server and the client reconnect based on the message retransmission strategy, the long connection gateway in the server can specifically reconnect the client according to the message retransmission period (such as specifically set to 2s, 5s, 10s, etc., of course, it is not limited to the period value, and can also be customized based on actual needs). The condition for stopping the execution of the above message retransmission strategy is to stop retransmitting the current message to the client when the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, or to meet the cumulative number of retransmissions of the current message to the client reaches the preset maximum number of retransmissions (for example, the preset maximum number of retransmissions can be set to any positive integer between 10-20).

[0081] Among them, when it is detected that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time length, it is triggered to stop retransmitting the current message to the client. It can also be simultaneously limited that the cumulative number of times the current message is retransmitted to the client does not exceed the preset maximum number of retransmissions. When the above two limiting conditions are met at the same time, it can be regarded that the server and the client have been disconnected and reconnected successfully. At this time, it is no longer necessary to retransmit the current message to the client based on the message retransmission strategy.

[0082] When it is detected that the cumulative number of times the current message is retransmitted to the client exceeds the preset maximum number of retransmissions, the current message is stopped from being retransmitted to the client, and it is deemed that the server and the client have failed to reconnect after disconnection. At this time, it is no longer necessary to retransmit the current message to the client based on the message retransmission strategy. The difference from the previous successful disconnection and reconnection situation is that after the server and the client fail to reconnect after disconnection, the server can also specifically generate fault detection notification information and send it to the corresponding target user terminal to notify the user corresponding to the target user terminal (such as the server operation and maintenance personnel) to promptly perform server or client fault inspection and repair, thereby promptly restoring the long connection between the client and the server.

[0083] It can be seen that the embodiment of the method can implement a WebSocket persistent connection based on the persistent connection gateway and push routing server in the Netty framework to ensure stable and efficient real-time communication between the server and the client, and can also ensure reliable delivery of messages and timely disconnection and reconnection when a network failure occurs between the server and the client.

[0084] Figure 8 is a schematic block diagram of a long connection communication system based on the Netty framework provided by an embodiment of the present invention. Figure 8 As shown, corresponding to the above long connection communication method based on Netty framework, the present invention also provides a long connection communication system 1 based on Netty framework. The long connection communication system 1 based on Netty framework includes: a client 10 and a server 20.

[0085] The client 10 is used to establish a WebSocket persistent connection based on the Netty framework with the server 20.

[0086] In this embodiment, in order to establish a stable long connection communication between the client and the server to maintain real-time communication, a WebSocket long connection based on the Netty framework can be established between the client and the long connection gateway in the server. Netty is a high-performance network programming framework, and the WebSocket protocol allows full-duplex communication on a single TCP (full name is Transmission Control Protocol, indicating the transmission control protocol) connection, which is suitable for application scenarios that require real-time data exchange, such as Bluetooth printing message push and client message notification. Moreover, the Netty framework specifically adopted in this application specifically sets at least a long connection gateway 22 and a push routing server 24. The long connection gateway 22 is the core part of maintaining a long connection between the server and the client, and the push routing server 24 correspondingly shares other processing functions of the long connection gateway 22 other than maintaining a long connection, such as message push routing control.

[0087] In one embodiment, the client 10 is used to:

[0088] Establishing a WebSocket connection with the server to obtain a user session corresponding to the client from the platform session control server in the server;

[0089] If the user session is verified, the user channel information corresponding to the client is sent to the server, so that the client establishes a WebSocket persistent connection with the persistent connection gateway.

[0090] In this embodiment, in order to more clearly understand the technical solution of the present application, Figure 1 and Figure 4 The Netty framework installed in the server 20 is introduced. Figure 1 and Figure 4 As shown, when the Netty framework is specifically installed in the server 20, it can be set to at least include a load balancing server 21, a persistent connection gateway 22, a platform session control server 23, a push routing server 24 and a Redis server 25. Afterwards, in combination with the Netty framework structure installed in the server 20, the specific process of establishing a WebSocket persistent connection between the client 10 and the server 20 is as follows:

[0091] 21) The client 10 and the server 20 initially establish a WebSocket connection, specifically, the client 10 establishes a WebSocket connection with the persistent connection gateway 22 in the server 20;

[0092] 22) The persistent connection gateway 22 obtains the user session corresponding to the client 10 from the platform session control server 23;

[0093] 23) The persistent connection gateway 22 verifies the user session, and when the user session passes the verification, the persistent connection gateway 22 obtains the user channel information corresponding to the user session (which can be represented by channel session), and sends it to the Redis server 25;

[0094] 24) The Redis server 25 receives the user channel information and writes it into the local storage space, and sends a notification message of successful writing of the user channel information to the persistent connection gateway 22;

[0095] 25) After receiving the write success notification message, the persistent connection gateway 22 establishes a WebSocket persistent connection with the client 10.

[0096] Among them, the Redis server 25 stores user channel information for different clients. For example, taking the client 10 in the above example as an example, the user channel information stored in the Redis server 25 at least includes a session control ID, a Netty channel ID, server information, and a channel push topic (represented by a channel topic). There are differences between the session control ID, Netty channel ID, server information, and channel push topic included in the user channel information corresponding to different clients. Preferably, each client corresponds to a unique session control ID and Netty channel ID to ensure the uniqueness of the long connection channel between the client and the server. The load balancing server 21 is used to perform load balancing processing when multiple different clients communicate with the server to ensure the availability and stability of the server.

[0097] After completing the WebSocket connection between the two, the client and the server achieve real-time communication. The client can receive communication messages from the server in real time and respond promptly.

[0098] In one embodiment, the client 10 is further configured to:

[0099] The heartbeat packet is sent to the server based on a preset heartbeat packet sending period, so that the Redis server in the server updates the renewal information of the user channel information corresponding to the client based on the reception time of the heartbeat packet.

[0100] In this embodiment, reference is still continued simultaneously Figure 1 and Figure 4 In order to maintain the WebSocket persistent connection between the client 10 and the server 20, the client 10 needs to send a heartbeat packet to the server based on a preset heartbeat packet sending cycle. Moreover, each time the server 20 receives a heartbeat packet sent by the client 10, specifically the persistent connection gateway 22 receives the heartbeat packet sent by the client 10, and then the persistent connection gateway 22 sends the heartbeat packet to the Redis server 25 to update the renewal information of the user channel information corresponding to the client 10 in the Redis server 25.

[0101] For example, the user channel information corresponding to the client 10 is stored in the Redis server 25, and the effective time of the long connection in the user channel information is determined by the time when the heartbeat packet sent by the client 10 was received last time. More specifically, the time when the Redis server 25 obtains the heartbeat packet sent by the client 10 last time is recorded as t1, and each time the Redis server 25 detects the time point of receiving the heartbeat packet, it automatically adds the preset effective duration T, such as taking t1+T as the renewal information corresponding to the updated user channel information. That is, in the corresponding time period of [t1, t1+T], the client 10 and the server 20 still maintain a WebSocket long connection. After t1+T is used as the renewal information corresponding to the updated user channel information in the Redis server 25 this time, t1+T is used as the new time when the heartbeat packet sent by the client 10 was received last time, and the renewal information of the user channel information corresponding to the client 10 is continued to be updated with reference to the above example when the heartbeat packet sent by the client 10 is received next time. It can be seen that based on the above-mentioned method of sending heartbeat packets, it is ensured that the client and the server continue to maintain a WebSocket long connection.

[0102] The server 10 is configured to send a current message corresponding to the communication request to the client if a communication request is detected.

[0103] In this embodiment, the reason why the long connection between the client and the server is ensured is that the server has the need to push messages or send requests to the client in real time. When the server detects or receives a user operation instruction (such as a Bluetooth printing instruction) from the user, it is necessary to promptly send a communication request corresponding to the user operation instruction to the client, specifically, to send the current message corresponding to the communication request to the client. After receiving the current message, the client needs to respond to it in a timely manner.

[0104] In one embodiment, taking a Bluetooth printing message push scenario as an example, the communication request is a Bluetooth printing request, the current message is a current Bluetooth printing message, and the server 10 is used to:

[0105] If the push routing server detects a Bluetooth print request, the current Bluetooth print message corresponding to the Bluetooth print request is obtained; wherein the current Bluetooth print message includes a current print message ID and a current print message body;

[0106] Obtaining current server information corresponding to the current Bluetooth printing message in the Redis server;

[0107] If the push routing server determines that the current confirmation message corresponding to the current Bluetooth printing message has not been received, determines that a WebSocket long connection has been established with the client, and determines that the current server information has passed the verification, then obtains the current user channel information from the Redis server;

[0108] The persistent connection gateway updates the current Bluetooth print message based on the current session control ID in the current user channel information, and sends the current Bluetooth print message to the client.

[0109] In this embodiment, continue to refer to Figure 1 and Figure 4 In the Bluetooth printing message push scenario, the client is a printing device with Bluetooth communication function. When the user uses the user terminal to send a Bluetooth printing instruction to the server 20 or the user directly operates the server 20 to generate a Bluetooth printing instruction, the server 20 first obtains the Bluetooth printing request corresponding to the Bluetooth printing instruction, and then obtains the current Bluetooth printing message corresponding to the Bluetooth printing request. The current Bluetooth printing message includes the current printing message ID (the current printing message ID can be directly the user ID corresponding to the client in specific implementation) and the current printing message body (which can be represented by msg).

[0110] Afterwards, the Redis server 25 in the server 20 obtains the current user channel information corresponding to the client 10 and the current Bluetooth print message, and parses and obtains the current server information included therein. The push routing server 24, under the condition that the current confirmation message corresponding to the current Bluetooth print message has not been received, a WebSocket long connection has been established with the client, and the current server information has been verified (wherein the current server information can be verified if it is not a null value), obtains the current user channel information again in full, and obtains the specific data included therein such as the current session control ID, the current Netty channel ID, the current server information, and the current channel push topic, etc. The push routing server 24 can send the current user channel information to the long connection gateway 22.

[0111] Finally, the current session control ID in the current user channel information is first obtained in the persistent connection gateway 22, and the current Bluetooth print message is updated with the current session control ID. Specifically, the current session control ID is added to the current Bluetooth print message, that is, in addition to retaining the current print message ID and the current print message body in the current Bluetooth print message, the current session control ID is also added, thereby obtaining the updated current Bluetooth print message, which is sent from the server to the client. It can be seen that based on the above method, the server can send the current message to the client in a timely manner based on the persistent connection.

[0112] The client 10 is further configured to generate a current confirmation message corresponding to the current message and send the message to the server if the current message is received.

[0113] In this embodiment, under the premise that the client and the server maintain a normal WebSocket long connection, after receiving the current message sent by the server, the client will promptly generate a current confirmation message corresponding to the current message and send it to the server. Among them, the current confirmation message can be understood as a confirmation message (which can be represented by ACK, the full name is Acknowledge character) required in the process of communication between the client and the server. After the client sends the current confirmation message to the server, the server may not be able to successfully receive the current confirmation message. For example, if the long connection between the client and the server is disconnected, the server needs to further confirm whether the current confirmation message is received.

[0114] In one embodiment, the client 10 is further used for:

[0115] Acquire the current session control ID in the current Bluetooth print message, and generate the current confirmation message corresponding to the current Bluetooth print message based on the current session control ID;

[0116] The current confirmation message is sent to the server.

[0117] In this embodiment, when generating the current confirmation message in the client, it is necessary to first obtain the current session control ID in the current Bluetooth print message, and then add the current session control ID to a preset confirmation message template to obtain the current confirmation message. Afterwards, the client sends the current confirmation message to the server so that the server can further determine whether the current confirmation message is successfully received. Only when the server receives the current confirmation message and determines that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, it means that the client has successfully received the current Bluetooth print message, and the accurate delivery of the message is ensured.

[0118] The server 20 is also used to save the current confirmation message in the push routing server in the server if the current confirmation message is received and it is determined that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time.

[0119] In this embodiment, if the persistent connection gateway in the server receives the current confirmation message and determines that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, it means that the current Bluetooth print message has been accurately delivered to the client, and the client can then perform corresponding content printing processing based on the current Bluetooth print message. Of course, before the client performs corresponding content printing processing based on the current Bluetooth print message, the current confirmation message can be first saved in the push routing server of the server and a mapping relationship with the current Bluetooth print message can be established.

[0120] In one embodiment, the server 20 is used to:

[0121] If the current confirmation message is received and it is determined that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, then obtaining the current session control ID in the current confirmation message, and generating a corresponding confirmation message identification value based on the current session control ID;

[0122] The confirmation message identification bit value in the current confirmation message is updated based on the confirmation message identification value, and the updated current confirmation message is saved.

[0123] In this embodiment, when the server specifically confirms in the persistent connection gateway that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, the server can first obtain the current session control ID included in the current confirmation message, and then generate a corresponding confirmation message identification value when it is determined that the current session control ID is not a null value, for example, the confirmation message identification value is represented by SID = 1. Of course, when it is determined that the current session control ID is a null value, a corresponding confirmation message identification value is generated, for example, the confirmation message identification value is represented by SID = 0.

[0124] After obtaining the confirmation message identification value in the persistent connection gateway, the confirmation message identification value can be used to replace the confirmation message identification bit value in the current confirmation message, thereby updating the confirmation message identification bit value in the current confirmation message, and obtaining the updated current confirmation message in the persistent connection gateway. Afterwards, the persistent connection gateway sends the current confirmation message to the push routing server and stores it in the push routing server. It can be seen that through the above method, the server can quickly confirm whether the current confirmation message has been received, and can also ensure reliable transmission of the message based on the current confirmation message.

[0125] The server 20 is also used to retransmit the current message to the client based on a preset message retransmission strategy if the current confirmation message is received and it is determined that the interval between the reception time of the current confirmation message and the sending time of the current message exceeds a preset detection time, or the long connection gateway in the server does not receive the current confirmation message.

[0126] In this embodiment, if the long connection gateway in the server receives the current confirmation message and determines that the interval between the reception time of the current confirmation message and the sending time of the current message exceeds the preset detection time, or the long connection gateway in the server does not receive the current confirmation message, it means that a disconnection has occurred between the server and the client. At this time, the current message can be retransmitted to the client based on the message retransmission strategy. The message retransmission strategy can be regarded as an intelligent disconnection and reconnection mechanism, which ensures that the communication between the server and the client will not be permanently interrupted in an unstable network environment, and supports the continued execution of tasks after disconnection, thereby improving the robustness of the system and ensuring business continuity.

[0127] In one embodiment, the server 20 is used to:

[0128] The current message is retransmitted to the client based on the message retransmission period in the message retransmission strategy, and retransmitting the current message to the client is stopped when it is detected that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time length, or retransmitting the current message to the client is stopped when it is detected that the cumulative number of times the current message is retransmitted to the client exceeds the preset maximum number of retransmissions.

[0129] In this embodiment, when the server and the client reconnect based on the message retransmission strategy, the long connection gateway in the server can specifically reconnect the client according to the message retransmission period (such as specifically set to 2s, 5s, 10s, etc., of course, it is not limited to the period value, and can also be customized based on actual needs). The condition for stopping the execution of the above message retransmission strategy is to stop retransmitting the current message to the client when the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, or to meet the cumulative number of retransmissions of the current message to the client reaches the preset maximum number of retransmissions (for example, the preset maximum number of retransmissions can be set to any positive integer between 10-20).

[0130] Among them, when it is detected that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time length, it is triggered to stop retransmitting the current message to the client. It can also be simultaneously limited that the cumulative number of times the current message is retransmitted to the client does not exceed the preset maximum number of retransmissions. When the above two limiting conditions are met at the same time, it can be regarded that the server and the client have been disconnected and reconnected successfully. At this time, it is no longer necessary to retransmit the current message to the client based on the message retransmission strategy.

[0131] When it is detected that the cumulative number of times the current message is retransmitted to the client exceeds the preset maximum number of retransmissions, the current message is stopped from being retransmitted to the client, and it is deemed that the server and the client have failed to reconnect after disconnection. At this time, it is no longer necessary to retransmit the current message to the client based on the message retransmission strategy. The difference from the previous successful disconnection and reconnection situation is that after the server and the client fail to reconnect after disconnection, the server can also specifically generate fault detection notification information and send it to the corresponding target user terminal to notify the user corresponding to the target user terminal (such as the server operation and maintenance personnel) to promptly perform server or client fault inspection and repair, thereby promptly restoring the long connection between the client and the server.

[0132] It can be seen that the embodiment of the system can implement WebSocket persistent connection based on the persistent connection gateway and push routing server in the Netty framework to ensure stable and efficient real-time communication between the server and the client, and can also ensure reliable delivery of messages and timely disconnection and reconnection when a network failure occurs between the server and the client.

[0133] The above-mentioned Netty framework-based long connection communication system can be implemented in the form of a computer program, which can be used in Fig. 9 Runs on the computer device shown.

[0134] See also Fig. 9 , Fig. 9 The present invention provides a schematic block diagram of a computer device provided in an embodiment of the present invention. The computer device integrates any of the Netty framework-based long connection communication systems provided in an embodiment of the present invention.

[0135] See also Fig. 9 The computer device 400 includes a processor 402 , a memory and a network interface 405 connected via a system bus 401 , wherein the memory may include a storage medium 403 and an internal memory 404 .

[0136] The storage medium 403 may store an operating system 4031 and a computer program 4032. The computer program 4032 includes program instructions, and when the program instructions are executed, the processor 402 may execute the above-mentioned long connection communication method based on the Netty framework.

[0137] The processor 402 is used to provide computing and control capabilities to support the operation of the entire computer device.

[0138] The internal memory 404 provides an environment for the operation of the computer program 4032 in the storage medium 403. When the computer program 4032 is executed by the processor 402, the processor 402 can execute the above-mentioned long connection communication method based on the Netty framework.

[0139] The network interface 405 is used to communicate with other devices over the network. Fig. 9 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present invention, and does not constitute a limitation on the computer device to which the solution of the present invention is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0140] The processor 402 is used to run a computer program 4032 stored in a memory to implement the long connection communication method based on the Netty framework as described above.

[0141] It should be understood that in the embodiment of the present invention, the processor 402 may be a central processing unit (CPU), and the processor 402 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0142] It can be understood by those skilled in the art that all or part of the processes in the method for implementing the above embodiment can be completed by instructing the relevant hardware through a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiment of the above method.

[0143] Therefore, the present invention also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the processor executes the long connection communication method based on the Netty framework as described above.

[0144] The computer-readable storage medium may be a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disk, etc., which are computer-readable storage media that can store program codes.

[0145] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0146] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of each unit is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.

[0147] The steps in the method of the embodiment of the present invention can be adjusted in order, combined and deleted according to actual needs. The units in the system of the embodiment of the present invention can be combined, divided and deleted according to actual needs. In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0148] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, terminal, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention.

[0149] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A long connection communication method based on the Netty framework, applied to a long connection communication system based on the Netty framework, characterized in that: The Netty framework-based persistent connection communication system includes a client and a server, and the Netty framework carried in the server includes at least a persistent connection gateway and a push routing server; The long connection communication method based on the Netty framework includes: The client establishes a WebSocket persistent connection based on the Netty framework with the persistent connection gateway in the server; If the server detects a communication request, the server sends a current message corresponding to the communication request to the client; If the client receives the current message, it generates a current confirmation message corresponding to the current message and sends it to the server; If the persistent connection gateway in the server receives the current confirmation message and determines that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, the push routing server in the server saves the current confirmation message; If the persistent connection gateway in the server receives the current confirmation message and determines that the interval between the reception time of the current confirmation message and the sending time of the current message exceeds the preset detection time, or the persistent connection gateway in the server does not receive the current confirmation message, the current message is retransmitted to the client based on the preset message retransmission strategy.

2. The method according to claim 1, characterized in that: The Netty framework carried by the server also includes a Redis server; the client and the persistent connection gateway in the server establish a WebSocket persistent connection based on the Netty framework, including: The client establishes a WebSocket connection with the persistent connection gateway in the server to obtain a user session corresponding to the client from the platform session control server in the server; If the client determines that the user session has passed the verification in the persistent connection gateway, the user channel information corresponding to the client is sent to the Redis server in the server, so that the client establishes a WebSocket persistent connection with the persistent connection gateway.

3. The method according to claim 2, characterized in that If the client determines that the user session is verified in the persistent connection gateway, after the step of sending user channel information corresponding to the client to the Redis server in the server so that the client establishes a WebSocket persistent connection with the persistent connection gateway, the method further includes: The client sends a heartbeat packet to the persistent connection gateway in the server based on a preset heartbeat packet sending period, so that the Redis server in the server updates the renewal information of the user channel information corresponding to the client based on the reception time of the heartbeat packet.

4. The method according to claim 1, characterized in that The Netty framework carried by the server also includes a Redis server; the communication request is a Bluetooth printing request, and the current message is a current Bluetooth printing message; If a communication request is detected, sending a current message corresponding to the communication request to the client includes: If the push routing server detects a Bluetooth print request, the current Bluetooth print message corresponding to the Bluetooth print request is obtained; wherein the current Bluetooth print message includes a current print message ID and a current print message body; Obtaining current server information corresponding to the current Bluetooth printing message in the Redis server; If the push routing server determines that the current confirmation message corresponding to the current Bluetooth printing message has not been received, determines that a WebSocket long connection has been established with the client, and determines that the current server information has passed the verification, then obtains the current user channel information from the Redis server; The persistent connection gateway updates the current Bluetooth print message based on the current session control ID in the current user channel information, and sends the current Bluetooth print message to the client.

5. The method according to claim 4, characterized in that If the current message is received, generating a current confirmation message corresponding to the current message and sending it to the server includes: Acquire the current session control ID in the current Bluetooth print message, and generate the current confirmation message corresponding to the current Bluetooth print message based on the current session control ID; The current confirmation message is sent to the server.

6. The method according to claim 5, characterized in that If the current confirmation message is received and it is determined that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, the push routing server in the server saves the current confirmation message, including: If the current confirmation message is received and it is determined that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time, then obtaining the current session control ID in the current confirmation message, and generating a corresponding confirmation message identification value based on the current session control ID; The confirmation message identification bit value in the current confirmation message is updated based on the confirmation message identification value, and the updated current confirmation message is saved.

7. The method according to claim 1, characterized in that The retransmitting the current message to the client based on a preset message retransmission strategy includes: The current message is retransmitted to the client based on the message retransmission period in the message retransmission strategy, and retransmitting the current message to the client is stopped when it is detected that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed the preset detection time length, or retransmitting the current message to the client is stopped when it is detected that the cumulative number of times the current message is retransmitted to the client exceeds the preset maximum number of retransmissions.

8. A long connection communication system based on Netty framework, characterized in that: It includes a client and a server, wherein the Netty framework carried in the server includes at least a persistent connection gateway and a push routing server; The client is used to establish a WebSocket persistent connection based on the Netty framework with the persistent connection gateway in the server; The server is configured to send a current message corresponding to the communication request to the client if a communication request is detected; The client is further configured to generate a current confirmation message corresponding to the current message and send the message to the server if the current message is received; The persistent connection gateway in the server is configured to, if the current confirmation message is received and it is determined that the interval between the reception time of the current confirmation message and the sending time of the current message does not exceed a preset detection time, store the current confirmation message in the push routing server in the server; The persistent connection gateway in the server is also used to retransmit the current message to the client based on a preset message retransmission strategy if the current confirmation message is received and it is determined that the interval between the reception time of the current confirmation message and the sending time of the current message exceeds a preset detection time length, or the persistent connection gateway in the server does not receive the current confirmation message.

9. A long connection communication system based on Netty framework, characterized in that: The invention comprises at least two computer devices, each of which comprises a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processors in at least two of the computer devices execute the corresponding computer programs, the long connection communication method based on the Netty framework as described in any one of claims 1 to 7 is jointly implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program includes program instructions. When the program instructions are executed by a processor, the long connection communication method based on the Netty framework as described in any one of claims 1 to 7 can be implemented.

Citation Information

Cited By

  • Method for safely accessing plug stream of video stream

    CN120751186A