Establishment method and device of long connection, equipment and storage medium

By testing whether the client belongs to the circular group and the establishment of a long connection under the necessary circumstances, it solves the problem of high -long connection costs and unable to cover the unsubscribed user account, and achieve the effect of reducing costs and covering more scenarios.

CN119383215APending Publication Date: 2025-01-28GUANGZHOU KUGOU COMP TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411563537.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-05
Publication Date
2025-01-28

AI Technical Summary

Technical Problem

The cost of establishing long-term connections in the prior art is high, and it cannot cover scenarios where the user has not logged in to the user account, resulting in users being unable to obtain information in time.

Method used

By detecting whether the client is a circular group, it is only a request to send a long connection to the server when it belongs to the circles only to avoid maintaining long connections based on the full amount of equipment.

Benefits of technology

Effectively reduce the power consumption of the establishment cost of long connection and the server maintained long connection, while covering a variety of scenarios, including the number of unbelized user accounts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119383215A_ABST
    Figure CN119383215A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a long connection establishment method and device, equipment and a storage medium, and relates to the technical field of computers. The method comprises the steps that in response to starting of a first client side, whether the first client side belongs to a delineated group or not is detected, and the delineated group comprises at least one client side selected to establish long connection with a server; and under the condition that the first client belongs to the delineated group, a long connection establishment request is sent to the server, and the long connection establishment request is used for requesting to establish long connection with the server. According to the method, only when the first client belongs to the delineated group, the establishment process of the long connection with the server is triggered, and when the first client does not belong to the delineated group, the long connection between the first client and the server does not need to be established. The long connection does not need to be fully maintained based on equipment, the establishment cost of the long connection can be effectively reduced, and the power consumption of the server for maintaining the long connection is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a method, apparatus, device and storage medium for establishing a persistent connection. Background Art

[0002] As a means to achieve real-time data exchange between servers and clients, long connections are widely used on the Internet.

[0003] In the related art, a method for establishing a persistent connection is provided, in which a persistent connection is established according to the full amount of devices, that is, all terminal devices installed with the client establish a persistent connection, and the server needs to maintain the full amount of persistent connections.

[0004] However, the above method will result in a high cost for establishing a long connection. Summary of the invention

[0005] The embodiment of the present application provides a method, apparatus, device and storage medium for establishing a long connection. The technical solution is as follows:

[0006] According to one aspect of an embodiment of the present application, a method for establishing a persistent connection is provided, the method being executed by a first client, the method comprising:

[0007] In response to the first client being started, detecting whether the first client belongs to a defined group, the defined group including at least one client selected to establish a persistent connection with a server;

[0008] In the case that the first client belongs to the defined group, a persistent connection establishment request is sent to the server, where the persistent connection establishment request is used to request to establish the persistent connection with the server.

[0009] According to one aspect of an embodiment of the present application, a device for establishing a long connection is provided, the device comprising:

[0010] a detection module, configured to detect, in response to the first client being started, whether the first client belongs to a defined group, wherein the defined group includes at least one client selected to establish a persistent connection with the server;

[0011] The sending module is used to send a persistent connection establishment request to the server when the first client belongs to the defined group, wherein the persistent connection establishment request is used to request to establish the persistent connection with the server.

[0012] According to one aspect of an embodiment of the present application, a terminal device is provided, which includes a processor and a memory, wherein a computer program is stored in the memory, and the computer program is loaded and executed by the processor to implement the above-mentioned method for establishing a long connection.

[0013] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is loaded and executed by a processor to implement the above-mentioned method for establishing a long connection.

[0014] According to one aspect of an embodiment of the present application, a computer program product is provided. The computer program product includes a computer program. The computer program is loaded and executed by a processor to implement the above-mentioned method for establishing a long connection.

[0015] The technical solution provided in the embodiments of the present application can bring the following beneficial effects:

[0016] The process of establishing a long connection with the server is triggered only when the first client belongs to the defined group. If the first client does not belong to the defined group, there is no need to establish a long connection between the first client and the server. There is no need to maintain a long connection based on the full amount of devices, which can effectively reduce the cost of establishing a long connection and reduce the power consumption of the server in maintaining a long connection. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 is a schematic diagram of a computer system provided by an embodiment of the present application;

[0018] Figure 2 This is a flowchart of a method for establishing a long connection provided by an embodiment of the present application;

[0019] Figure 3 is a flowchart of a method for establishing a long connection provided by another embodiment of the present application;

[0020] Figure 4 is a flowchart of a method for establishing a long connection provided by another embodiment of the present application;

[0021] Figure 5 is a block diagram of a device for establishing a long connection provided by an embodiment of the present application;

[0022] Figure 6 It is a structural diagram of a terminal device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0023] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0024] Please refer to Figure 1 , which shows a schematic diagram of a computer system provided by an embodiment of the present application. The computer system can be implemented as a long connection establishment system. The computer system may include: a terminal device 10 and a server 20.

[0025] The number of terminal devices 10 may be one or more. The terminal device 10 may be an electronic device such as a mobile phone, a tablet computer, a laptop computer, a desktop computer, a game console, an e-book reader, a multimedia player, a wearable device, a smart TV, a vehicle-mounted terminal, etc. The first client corresponding to the target application may be installed in the terminal device 10. Optionally, the target application may be an application that needs to be downloaded and installed, or may be a point-and-click application, which is not limited in the embodiment of the present application. In the embodiment of the present application, the above-mentioned target application is an application with a function of establishing a long connection. Of course, the specific type of the target application is not limited, and the type of the target application may be a music application, a video application, an animation application, a social application, a question-and-answer application, a virtual reality application, an augmented reality application, etc. The embodiment of the present application does not limit the specific category of the target application. In other embodiments, the target application may be considered as a separate functional module, such as being implemented as one of the functional modules in the music application for implementing the establishment of a long connection. Exemplarily, the above-mentioned first client is running in the terminal device 10.

[0026] The server 20 is used to provide background services for the client of the target application installed and running in the terminal device 10. For example, the server 20 can be the background server of the above-mentioned target application. The server 20 can be a single server, or a server cluster composed of multiple servers, or a cloud computing service center. Optionally, the server 20 provides background services for the clients of the target application in multiple terminal devices 10 at the same time. The terminal device 10 and the server 20 can communicate with each other through the network.

[0027] In some embodiments, in response to the first client being started, it is detected whether the first client belongs to a defined group, the defined group including at least one client selected to establish a long connection with the server; if the first client belongs to the defined group, a long connection establishment request is sent to the server, the long connection establishment request being used to request to establish the long connection with the server.

[0028] The method provided in the embodiment of the present application may be performed by a computer device. The computer device may be any electronic device that has the ability to store and process data. For example, the computer device may be Figure 1 The terminal device 10 may also be a server 20.

[0029] HTTP (Hypertext Transfer Protocol) is one of the cornerstones of modern Internet communication. It defines the rules for data exchange between clients and servers. In HTTP communication, there are two main connection modes: short connection and long connection. Short connection means that a new TCP (Transmission Control Protocol) connection is established for each request-response interaction. This means that each HTTP request needs to go through the TCP three-way handshake and four-wave handshake process, which consumes time and resources. Once the response is completed, the connection is closed immediately. Long connection (also called persistent connection or HTTP Keep-Alive) allows multiple request-response interactions on the same connection. In this way, the TCP connection between the client and the server remains open for a period of time and can be reused without having to repeatedly establish and close the connection. This greatly reduces the overhead of connection establishment and teardown, improving performance and efficiency.

[0030] There are many advantages to using HTTP persistent connections, especially in high-traffic and high-concurrency scenarios:

[0031] 1. Reduce the overhead of connection establishment and removal: Long connections avoid unnecessary TCP handshake and wave processes, reducing network delays and resource consumption.

[0032] 2. Improved performance: Persistent connections between clients and servers allow more request-response interactions, thereby speeding up data transfer.

[0033] 3. Reduce server load: Long connections reduce the number of connections opened simultaneously on the server, reduce the burden on the server, and improve scalability.

[0034] 4. Better user experience: Users can load web pages and applications faster because the connection remains open, reducing waiting time.

[0035] In the related art, there are two situations regarding the method of establishing a long connection. One is to establish a long connection according to the full amount of devices. That is, all terminal devices with the client installed establish a long connection, which results in a high cost for establishing a long connection. The other is to establish a long connection according to the user account. That is, only the client that logs in to the user account establishes a long connection, and the client that does not log in to the user account does not establish a long connection. This situation cannot cover the scenario of the user account not being logged in, and may cause the user to be unable to obtain information in a timely manner.

[0036] An embodiment of the present application provides a method for establishing a persistent connection, which can determine the client that needs to establish a persistent connection according to a defined range, while reducing the cost of establishing a persistent connection and covering a variety of scenarios including user accounts that are not logged in.

[0037] Please refer to Figure 2 , which shows a flow chart of a method for establishing a long connection provided by an embodiment of the present application. The method includes at least one of the following steps 210 to 220.

[0038] Step 210 , in response to the first client being started, the first client detects whether the first client belongs to a defined group, where the defined group includes at least one client selected to establish a persistent connection with the server.

[0039] Client, or user end, refers to a program that corresponds to a server and provides local services to users. In addition to some applications that only run locally, they are generally installed on ordinary terminal devices and need to cooperate with the server to run. After the development of the Internet, the more commonly used user ends include web browsers used for the World Wide Web, email clients for sending and receiving emails, and instant messaging client software. For this type of application, there needs to be a corresponding server and service program in the network to provide corresponding services, such as database services, email services, etc. In this way, a specific communication connection needs to be established between the terminal device and the server to ensure the normal operation of the application.

[0040] In some embodiments, the defined group is determined by the server. In some embodiments, the defined group may be fixed or dynamically changed. Exemplarily, the defined group may change following the planning of the first client. Exemplarily, if the first client carries out a planning activity, such as a lottery, then the defined group may be the first client that is eligible to participate in the planning activity. Exemplarily, if the first client launches a new version of the internal testing activity, then the defined group may be the first client that has been updated to the internal testing version. In some embodiments, the defined group may be determined based on the operating conditions of the first client, the user portrait of the first client, etc., and this application does not limit this, and the above content is only illustrated as an exemplary embodiment.

[0041] In some embodiments, the first client is installed and runs on the first terminal device. In some embodiments, the first client startup refers to the first client startup on the first terminal device. In some embodiments, after the first client is started, it can run in the foreground or in the background, which is not limited in this application. In some embodiments, the startup of the first client can be triggered by the user or by the operating system of the first terminal device, which is not limited in this application. Exemplarily, the startup of the first client can be triggered based on the user's startup operation. Exemplarily, the startup of the first client can be triggered with the startup of the operating system of the first terminal device.

[0042] In some embodiments, detecting whether the first client belongs to the defined group can be based on a mark cached by the first client, or can be performed by sending a query message to the server, which is not limited in this application. Exemplarily, the first client caches a first mark, and the first mark is used to indicate that the client belongs to the defined group within a first time period, so the first client is considered to belong to the defined group. Exemplarily, the first client caches a second mark, and the second mark is used to indicate that the client does not belong to the defined group within a second time period, so the first client is considered not to belong to the defined group. Exemplarily, the first client sends a query message to the server, and the query message is used to query whether the first client belongs to the defined group, and determines whether the first client belongs to the defined group based on the response information fed back by the server.

[0043] Step 220: When the first client belongs to the defined group, the first client sends a persistent connection establishment request to the server, where the persistent connection establishment request is used to request to establish a persistent connection with the server.

[0044] In some embodiments, when the first client belongs to a defined group, the first client sends a persistent connection establishment request to the server to trigger a persistent connection establishment process.

[0045] In some embodiments, when the first client does not belong to the defined group, the first client does not send a persistent connection establishment request, and there is no need to trigger a persistent connection establishment process.

[0046] In some embodiments, after receiving the persistent connection establishment response sent by the server, the persistent connection establishment is completed. The first client and the server can communicate through the persistent connection.

[0047] In some embodiments, the long connection will not be actively closed, and subsequent read and write operations will continue to use this connection. Under normal circumstances, after a TCP long connection is established, as long as both parties do not make a closing request and no abnormal situation occurs, this connection will always exist. The operating system will not automatically close it, and it can still be used even after the physical network topology changes. Therefore, it is possible for a connection to remain for several days, months, years or even longer, as long as there is no abnormal situation or it is actively closed by the user (application layer). The first client and the server can always use this connection for data communication. Long connections can save more TCP establishment and closing operations, reduce the impact of network congestion, and when an error occurs, prompts can be given without closing the connection, reducing the use of CPU and memory because there is no need to frequently establish and close connections.

[0048] The technical solution provided by the embodiment of the present application triggers the process of establishing a long connection with the server only when the first client belongs to the defined group. If the first client does not belong to the defined group, there is no need to establish a long connection between the first client and the server. There is no need to maintain a long connection based on the full amount of devices, which can effectively reduce the cost of establishing a long connection and reduce the power consumption of the server in maintaining a long connection.

[0049] How to determine whether the first client belongs to the defined group

[0050] 1. Determine by sending a query message to the server

[0051] In some embodiments, please refer to Figure 3 , the above step 210 can be implemented as at least one of the following steps 211 to 230.

[0052] Step 211: The first client sends query information to the server, where the query information is used to query whether the first client belongs to a defined group.

[0053] Step 212: The first client receives response information sent by the server, where the response information is used to indicate whether the first client belongs to a defined group.

[0054] Step 213: The first client determines whether the first client belongs to or does not belong to the defined group based on the response information.

[0055] In some embodiments, the response information may directly indicate whether the first client belongs to a defined group, or may indirectly indicate whether the first client belongs to a defined group, which is not limited in the present application.

[0056] In some embodiments, the response information directly or indirectly indicates whether the first client belongs to a defined group, which may affect the information carried in the query information and the response information. The two situations will be discussed below in a classified manner.

[0057] Case 1: The response information directly indicates whether the first client belongs to the defined group

[0058] In some embodiments, after receiving the query information, the server determines whether the first client belongs to a defined group.

[0059] In some embodiments, the query information includes relevant information of the first client. In some embodiments, after receiving the query information, the server determines whether the first client belongs to a defined group based on the relevant information of the first client included in the query information.

[0060] In some embodiments, the query information does not include relevant information of the first client. After receiving the query information, the server instructs the first client to report relevant information of the first client, and after obtaining the relevant information of the first client, determines whether the first client belongs to the defined group.

[0061] In some embodiments, the relevant information of the first client is used by the server to determine whether the first client belongs to a defined group. Exemplarily, the relevant information of the first client includes at least one of the following information: identification information of the first client, login information of the first client, user portrait corresponding to the first client, and geographic location corresponding to the first client. Login information refers to whether the first client is logged in to the user account. User portrait is a labeled user model abstracted from various characteristics and behaviors of the user, which can help precision marketing, user research, personalized services and business decisions. Geographical location refers to the geographical location of the first terminal device where the first client is installed and running.

[0062] In some embodiments, the response information includes first indication information or second indication information, the first indication information is used to indicate that the first client belongs to a defined group, and the second indication information is used to indicate that the first client does not belong to the defined group. In some embodiments, when the first client belongs to the defined group, the response information sent by the server carries the first indication information; when the first client does not belong to the defined group, the response information sent by the server carries the second indication information.

[0063] In some embodiments, when the first client belongs to the defined group, the server sends a response message, and the response message is used to indicate that the first client belongs to the defined group; when the first client does not belong to the defined group, the server does not send a response message, and the first client does not receive the response message, which means that the first client does not belong to the defined group. In some embodiments, the first client does not receive the response message within the third time period, which means that the first client does not belong to the defined group. In some embodiments, the start time of the third time period is the time when the query information is sent.

[0064] Case 2: The response information indirectly indicates whether the first client belongs to the defined group

[0065] In some embodiments, after receiving the response information, the first client determines whether the first client belongs to the defined group based on the content carried in the response information.

[0066] In some embodiments, the response information includes first condition information, and the first condition information is used to indicate the characteristics of the client belonging to the defined group. In some embodiments, after receiving the response information, the first client determines whether the first client belongs to the defined group based on the first condition information.

[0067] In some embodiments, the first condition information includes at least one of the following:

[0068] The first sub-information is used to indicate whether the client belonging to the defined group has logged into the user account;

[0069] The second sub-information is used to indicate the conditions satisfied by the user profile corresponding to the client belonging to the defined group;

[0070] The third sub-information is used to indicate the conditions satisfied by the geographical locations corresponding to the clients belonging to the defined group.

[0071] In some embodiments, the first client determines whether the first client belongs to the defined group based on the first condition information. In some embodiments, if the first condition information is met, the first client belongs to the defined group; if the first condition information is not met, the first client does not belong to the defined group.

[0072] In some embodiments, the features of the client belonging to the defined group may also include other information, and the above three sub-information are only used as examples for explanation here. Exemplarily, the features of the client belonging to the defined group are defined based on the new function of the first client. For example, when a new function is grayed out, select a suitable client, including a client with a logged-in user account or a client with a non-logged-in user account; for example, pay attention to the experience of the young user group and define the client with a young user account logged in; for example, pay attention to the experience of the non-logged-in user and define the client with a non-logged-in user account, and so on.

[0073] In some embodiments, the response information includes first range information, and the first range information is used to indicate a restricted group. In some embodiments, the first range information includes identification information of clients belonging to the restricted group.

[0074] In some embodiments, if the first range information includes identification information of the first client, it indicates that the first client belongs to a defined group; if the first range information does not include identification information of the first client, it indicates that the first client does not belong to the defined group.

[0075] 2. Determined by local cache tag

[0076] In some embodiments, when the first client belongs to a defined group, a first flag is cached, where the first flag is used to indicate that the first client belongs to the defined group within a first time period.

[0077] In some embodiments, when the first client does not belong to the defined group, a second flag is cached, where the second flag is used to indicate that the first client does not belong to the defined group during the second period of time.

[0078] When the first client belongs to the defined group, the first mark is cached, and when the first client does not belong to the defined group, the second mark is cached. In this way, when it is necessary to detect whether the first client belongs to the defined group next time, the mark cached by the first client can be used to determine whether it belongs to the defined group. In some embodiments, since the defined group can be variable, a valid time can be assigned to the mark, and the first mark is valid in the first time period, and the second mark is valid in the second time period.

[0079] In some embodiments, in response to the first client starting, the query information is used to determine whether the first client belongs to the defined group. In some embodiments, the start time of the first period and the start time of the second period are both the time when the response information is received, and the response information is used to indicate whether the first client belongs to the defined group.

[0080] In some embodiments, in response to the first client being started, the first client receives notification information broadcast by the server, and the notification information includes first condition information or first range information. The first client can determine whether the first client belongs to the defined group based on the notification information. In some embodiments, the start time of the first time period and the start time of the second time period are both the reception time of the notification information, and the notification information is used to indicate whether the first client belongs to the defined group.

[0081] In some embodiments, the duration of the first time period and / or the second time period may be indicated by the server or may be preconfigured. Exemplarily, the response information and / or the notification information also includes first duration information, and the first duration information is used to indicate the duration of the first time period and / or the second time period. In some embodiments, the starting time of the first time period and / or the second time period may also be indicated by the server. Exemplarily, the response information and / or the notification information also includes first time information, and the first duration information is used to indicate the starting time of the first time period and / or the second time period.

[0082] In some embodiments, the duration of the first time period may be the same as or different from the duration of the second time period, and this application does not limit this. For example, the duration of the first time period is t1, and the duration of the second time period is t2, and t1 may be equal to t2 or may not be equal to t2. In some embodiments, the duration of the first time period or the duration of the second time period may also be 0.

[0083] In some embodiments, the first mark or the second mark may also be cached locally when the first client was last started, and the startup and shutdown of the first client does not affect the timing of the first time period or the second time period. In some embodiments, the shutdown of the first client means that the first client stops running, and the long connection with the server will be disconnected after the first client stops running. Exemplarily, the first client caches the first mark when it is started for the first time, and when it is started for the second time, it is still in the first time period, so there is no need to detect again whether the first client belongs to the defined group, and directly send a long connection establishment request to the server.

[0084] In some embodiments, in the first time period, in response to the effective duration of the long connection timing out, the first client again sends a long connection establishment request to the server. In some embodiments, since the defined group can change dynamically, the server can assign a valid duration to the long connection. During the valid duration, the server will not actively disconnect the long connection between the first client and the server. After the effective duration times out, the server actively disconnects the long connection with the first client. At this time, if it is still in the first time period, the first client sends a long connection establishment request to the server again to establish a new long connection. In some embodiments, in the second time period, the first client does not send a long connection establishment request to the server.

[0085] In some embodiments, when the network status of the first client changes (such as mobile network & Wifi (Wireless Fidelity) switching, disconnection, reconnection), the long connection will also be disconnected. Some other force majeure factors such as poor network status, DHCP (Dynamic Host Configuration Protocol) lease expiration, etc. will cause the long connection to be disconnected. After the long connection is disconnected, if it is still within the first time period, there is no need to re-detect whether the first client belongs to the circled range, and a long connection establishment request can be sent directly to the server.

[0086] In some embodiments, after the first period or the second period times out, the first client may also update the first mark or the second mark.

[0087] In some embodiments, in response to the end of the first time period or the second time period, it is detected again whether the first client belongs to the circled group; when the first client changes from belonging to the circled group to not belonging to the circled group, the cached first mark is updated to the second mark; when the first client changes from not belonging to the circled group to belonging to the circled group, the cached second mark is updated to the first mark.

[0088] Regarding detecting whether the first client belongs to a defined group, reference may be made to the description of the above embodiment, and the present application will not elaborate on it here.

[0089] In some embodiments, when the first client changes from belonging to the defined group to not belonging to the defined group, the cached first mark is updated to the second mark, and the valid period is updated from the first period to the second period; when the first client changes from not belonging to the defined group to belonging to the defined group, the cached second mark is updated to the first mark, and the valid period is updated from the second period to the first period.

[0090] In some embodiments, when the first client still belongs to the defined group, the first time period is extended. In some embodiments, the third time period is extended based on the first time period. In some embodiments, the third time period may be the same as the first time period or may be different from the first time period, and this application does not limit this. In some embodiments, the third time period may be pre-configured or may be configured by the server based on the method of determining the defined group.

[0091] In some embodiments, when the first client still does not belong to the defined group, the second time period is extended. In some embodiments, the fourth time period is extended based on the second time period. In some embodiments, the fourth time period may be the same as the second time period or may be different from the second time period, and this application does not limit this. In some embodiments, the fourth time period may be preconfigured or may be configured by the server based on the method of determining the defined group.

[0092] 3. Periodically check whether the first client belongs to the defined group

[0093] In some embodiments, after the first client is started, the first client periodically detects whether the first client belongs to a defined group.

[0094] In some embodiments, when the first client is closed, the persistent connection between the first client and the server is disconnected. In some embodiments, after detecting that the first client switches from belonging to a defined group to not belonging to a defined group, the persistent connection between the first client and the server is disconnected.

[0095] In some embodiments, the period for detecting whether the first client belongs to the defined group is indicated by the server. Exemplarily, the server indicates the first time period through a response message or a notification message, and the first time period is used to indicate the period duration for detecting whether the first client belongs to the defined group. In some embodiments, if the query message is used to detect whether the first client belongs to the defined group, the start time of the periodic detection is the time when the query message is sent. In some embodiments, if the notification message is used to obtain whether the first client belongs to the defined group, the start time of the periodic detection is the time when the notification message is received. In some embodiments, if the notification message is used to obtain whether the first client belongs to the defined group, the server can periodically send notification messages, and the first client only needs to periodically receive notification messages.

[0096] In some embodiments, the first time period may be predefined or determined by the server. For example, the first time period may be determined by the server based on the network status of the first client. If the network status of the first client is poor, the first time period may be shorter; if the network status of the first client is better, the first time period may be longer.

[0097] The technical solution provided in the embodiment of the present application triggers the process of establishing a long connection with the server only when the first client belongs to the defined group. When the first client does not belong to the defined group, there is no need to establish a long connection between the first client and the server. There is no need to maintain a long connection based on the full amount of the device, which can effectively reduce the cost of establishing a long connection and reduce the power consumption of the server to maintain a long connection. Clients that are not logged in to the user account can also establish a long connection, and clients that are logged in to the user account can also establish a long connection on demand, which can reduce the cost of establishing a long connection while covering more scenario requirements.

[0098] Please refer to Figure 4 , which shows a flowchart of a method for establishing a long connection provided by an embodiment of the present application.

[0099] The target user account / device is determined by the server. There are many scenarios for defining the user range. The scenarios for defining the target group as needed are as follows: for example, when a new feature is grayed out, select appropriate users, including logged-in users or non-logged-in users; for example, focus on the overall experience of young users and define all young accounts; for example, focus on the experience of non-logged-in users and define non-logged-in devices, etc.

[0100] The front end (first client) obtains whether the current account / device needs to establish a long connection, and automatically queries when the first client is started, without user operation.

[0101] In addition, there is no need to query and establish a persistent connection every time. A control time period can be issued, and logged-in users can also connect on demand. The control period is to query whether to establish a persistent connection mark, and then cache the mark locally on the client for a period of time; if there is a mark locally, there is no need to query the mark again at startup. There are many ways here, such as caching for a period of time t1 with a mark, not caching without a mark, or caching for a period of time t2 (t1 does not necessarily have to be equal to t2); in addition, it is not necessary to only start the call, but also to call periodically.

[0102] Taking the music application as an example, the first client is a music client. In response to the music client being started, the music client detects whether the music client belongs to a defined group, which includes at least one client selected to establish a long connection with the server. If the music client belongs to the defined group, the music client sends a long connection establishment request to the server, which is used to request to establish a long connection with the server. After the long connection is established, the music client can realize real-time data exchange with the server. Exemplarily, the user can listen to songs on the music client without downloading or caching.

[0103] Taking a game application as an example, the first client is a game client. In response to the game client being started, the game client detects whether the game client belongs to a defined group, which includes at least one client selected to establish a long connection with the server. If the game client belongs to the defined group, the game client sends a long connection establishment request to the server, which is used to request to establish a long connection with the server. After the long connection is established, the game client can realize real-time data exchange with the server. Exemplarily, after the long connection is established, the game client can provide a better quality image service.

[0104] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.

[0105] Please refer to Figure 5 , which shows a block diagram of a device for establishing a long connection provided by an embodiment of the present application. The device has the function of implementing the above method example, and the function can be implemented by hardware, or by hardware executing corresponding software. The device can be the first terminal device introduced above, or it can be set in the first terminal device. Figure 5 As shown, the device 500 may include: a detection module 510 and a sending module 520.

[0106] The detection module 510 is configured to detect, in response to the first client being started, whether the first client belongs to a defined group, wherein the defined group includes at least one client selected to establish a persistent connection with the server.

[0107] The sending module 520 is used to send a persistent connection establishment request to the server when the first client belongs to the defined group, wherein the persistent connection establishment request is used to request to establish the persistent connection with the server.

[0108] In some embodiments, the detection module 510 is used to send query information to the server, the query information is used to query whether the first client belongs to the defined group; receive response information sent by the server, the response information is used to indicate whether the first client belongs to the defined group; based on the response information, determine whether the first client belongs to the defined group.

[0109] In some embodiments, the response information includes first indication information, and the first indication information is used to indicate that the first client belongs to the defined group; or, the response information includes first condition information, and the first condition information is used to indicate characteristics of the client belonging to the defined group; or, the response information includes first range information, and the first range information is used to indicate the defined group.

[0110] In some embodiments, the first condition information includes at least one of the following:

[0111] The first sub-information is used to indicate whether the client belonging to the defined group has logged into the user account;

[0112] The second sub-information is used to indicate the conditions satisfied by the user profile corresponding to the client belonging to the defined group;

[0113] The third sub-information is used to indicate the conditions satisfied by the geographical locations corresponding to the clients belonging to the defined group.

[0114] In some embodiments, the device 500 further includes a cache module (not shown).

[0115] The cache module is used to cache a first mark when the first client belongs to the defined group, and the first mark is used to indicate that the first client belongs to the defined group within a first time period; and cache a second mark when the first client does not belong to the defined group, and the second mark is used to indicate that the first client does not belong to the defined group within a second time period; wherein the start time of the first time period and the start time of the second time period are both the reception time of response information, and the response information is used to indicate whether the first client belongs to the defined group.

[0116] In some embodiments, the sending module 520 is further configured to, in response to a timeout of the effective duration of the persistent connection within the first time period, send the persistent connection establishment request to the server again.

[0117] In some embodiments, the cache module is also used to detect again whether the first client belongs to the defined group in response to the end of the first time period or the second time period; when the first client changes from belonging to the defined group to not belonging to the defined group, the cached first mark is updated to the second mark; when the first client changes from not belonging to the defined group to belonging to the defined group, the cached second mark is updated to the first mark.

[0118] In some embodiments, the detection module 510 is further used to periodically detect whether the first client belongs to the defined group after the first client is started.

[0119] The technical solution provided by the embodiment of the present application triggers the process of establishing a long connection with the server only when the first client belongs to the defined group. If the first client does not belong to the defined group, there is no need to establish a long connection between the first client and the server. There is no need to maintain a long connection based on the full amount of devices, which can effectively reduce the cost of establishing a long connection and reduce the power consumption of the server in maintaining a long connection.

[0120] It should be noted that the device provided in the above embodiment only uses the division of the above-mentioned functional modules as an example to implement its functions. In practical applications, the above-mentioned functions can be assigned to different functional modules according to actual needs, that is, the content structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0121] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0122] Please refer to Figure 6 , which shows a block diagram of a terminal 600 provided in one embodiment of the present application. The terminal 600 may be an electronic device such as a mobile phone, a tablet computer, a game console, an e-book reader, a multimedia player, a wearable device, a PC, etc. The terminal is used to implement the method for establishing a long connection provided in the above embodiment. The terminal may be Figure 1 The terminal 10 shown. Specifically:

[0123] Typically, the terminal 600 includes a processor 601 and a memory 602 .

[0124] The processor 601 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 601 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field Programmable Gate Array), and PLA (Programmable Logic Array). The processor 601 may also include a main processor and a coprocessor. The main processor is a processor for processing data in an awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 601 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 601 may also include an AI processor, which is used to process computing operations related to machine learning.

[0125] The memory 602 may include one or more computer-readable storage media, which may be non-transitory. The memory 602 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 602 is used to store at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is configured to be executed by one or more processors to implement the above-mentioned virtual object control method.

[0126] In some embodiments, the terminal 600 may further optionally include: a peripheral device interface 603 and at least one peripheral device. The processor 601, the memory 602 and the peripheral device interface 603 may be connected via a bus or a signal line. Each peripheral device may be connected to the peripheral device interface 603 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency circuit 604, a display screen 605, a camera 606, an audio circuit 607, a positioning component 608 and a power supply 609.

[0127] Those skilled in the art will understand that Figure 6 The structure shown in the figure does not constitute a limitation on the terminal 600, and the terminal 600 may include more or less components than those shown in the figure, or combine some components, or adopt a different component arrangement.

[0128] For details not described in detail in this embodiment, please refer to the above embodiments, which will not be described in detail here.

[0129] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is used to be executed by a processor of a terminal device to implement the above-mentioned method for establishing a long connection.

[0130] Optionally, the computer readable storage medium may include: ROM (Read-Only Memory), RAM (Random-Access Memory), SSD (Solid State Drives) or optical disks, etc. Among them, the random access memory may include ReRAM (Resistance Random Access Memory) and DRAM (Dynamic Random Access Memory).

[0131] An embodiment of the present application also provides a computer program product, which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the terminal device reads and executes the computer instructions from the computer-readable storage medium to implement the above-mentioned method for establishing a long connection.

[0132] In the description of the embodiments of the present application, the term "corresponding" may indicate a direct or indirect correspondence between two items, or an association relationship between the two items, or a relationship between indication and being indicated, configuration and being configured, and the like.

[0133] The term "multiple" as used herein refers to two or more than two. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects are in an "or" relationship.

[0134] In addition, the step numbers described in this document only illustrate a possible execution order between the steps. In some other embodiments, the above steps may not be executed in the order of the numbers, such as two steps with different numbers are executed at the same time, or two steps with different numbers are executed in the opposite order to that shown in the figure. The embodiments of the present application are not limited to this.

[0135] In addition, the embodiments provided herein may be arbitrarily combined to form new embodiments, which are all within the protection scope of the present application.

[0136] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the embodiments of the present application can be implemented with hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein the communication media include any media that facilitates the transmission of a computer program from one place to another. The storage medium can be any available medium that a general or special-purpose computer can access.

[0137] The above description is only an exemplary embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.

Claims

1. A method for establishing a long connection, characterized in that: The method is performed by a first client, and includes: In response to the first client being started, detecting whether the first client belongs to a defined group, the defined group including at least one client selected to establish a persistent connection with a server; In the case that the first client belongs to the defined group, a persistent connection establishment request is sent to the server, where the persistent connection establishment request is used to request to establish the persistent connection with the server.

2. The method according to claim 1, characterized in that The detecting whether the first client belongs to a defined group includes: Sending query information to the server, wherein the query information is used to query whether the first client belongs to the defined group; receiving a response message sent by the server, wherein the response message is used to indicate whether the first client belongs to the defined group; Based on the response information, it is determined whether the first client belongs to or does not belong to the defined group.

3. The method according to claim 2, characterized in that The response information includes first indication information, where the first indication information is used to indicate that the first client belongs to the defined group; or, The response information includes first condition information, where the first condition information is used to indicate characteristics of the client belonging to the defined group; or The response information includes first range information, where the first range information is used to indicate the defined group.

4. The method according to claim 3, characterized in that: The first condition information includes at least one of the following: The first sub-information is used to indicate whether the client belonging to the defined group has logged into the user account; The second sub-information is used to indicate the conditions satisfied by the user profile corresponding to the client belonging to the defined group; The third sub-information is used to indicate the conditions satisfied by the geographical locations corresponding to the clients belonging to the defined group.

5. The method according to claim 1, characterized in that The method further comprises: In the case where the first client belongs to the defined group, caching a first mark, the first mark being used to indicate that the first client belongs to the defined group within a first time period; If the first client does not belong to the defined group, cache a second flag, where the second flag is used to indicate that the first client does not belong to the defined group within a second time period; The start time of the first time period and the start time of the second time period are both the time when the response information is received, and the response information is used to indicate whether the first client belongs to the defined group.

6. The method according to claim 5, characterized in that The method further comprises: In the first time period, in response to the effective duration of the persistent connection timing out, the persistent connection establishment request is sent to the server again.

7. The method according to claim 5, characterized in that The method further comprises: In response to the first time period or the second time period ending, detecting again whether the first client belongs to the defined group; When the first client changes from belonging to the defined group to not belonging to the defined group, updating the cached first mark to the second mark; When the first client changes from not belonging to the defined group to belonging to the defined group, the cached second mark is updated to the first mark.

8. The method according to claim 1, characterized in that: The method further comprises: After the first client is started, it is periodically detected whether the first client belongs to the defined group.

9. A device for establishing a long connection, characterized in that: The device comprises: a detection module, configured to detect, in response to the first client being started, whether the first client belongs to a defined group, wherein the defined group includes at least one client selected to establish a persistent connection with the server; The sending module is used to send a persistent connection establishment request to the server when the first client belongs to the defined group, wherein the persistent connection establishment request is used to request to establish the persistent connection with the server.

10. A terminal device, characterized in that: The terminal device includes a processor and a memory, wherein a computer program is stored in the memory, and the computer program is loaded and executed by the processor to implement the method for establishing a long connection as described in any one of claims 1 to 9.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is loaded and executed by a processor to implement the method for establishing a long connection according to any one of claims 1 to 9.

12. A computer program product, characterized in that The computer program product comprises a computer program, and the computer program is loaded and executed by a processor to implement the method for establishing a long connection according to any one of claims 1 to 9.