WO2017041381A1 - 多业务共享长连接方法、系统及其装置、终端 - Google Patents

多业务共享长连接方法、系统及其装置、终端 Download PDF

Info

Publication number
WO2017041381A1
WO2017041381A1 PCT/CN2015/097955 CN2015097955W WO2017041381A1 WO 2017041381 A1 WO2017041381 A1 WO 2017041381A1 CN 2015097955 W CN2015097955 W CN 2015097955W WO 2017041381 A1 WO2017041381 A1 WO 2017041381A1
Authority
WO
WIPO (PCT)
Prior art keywords
heartbeat time
long
server
heartbeat
service
Prior art date
Application number
PCT/CN2015/097955
Other languages
English (en)
French (fr)
Inventor
田纪胜
Original Assignee
深圳创维-Rgb电子有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳创维-Rgb电子有限公司 filed Critical 深圳创维-Rgb电子有限公司
Priority to AU2015400309A priority Critical patent/AU2015400309B2/en
Priority to US15/414,627 priority patent/US10263872B2/en
Publication of WO2017041381A1 publication Critical patent/WO2017041381A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/10Active monitoring, e.g. heartbeat, ping or trace-route
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/04Processing captured monitoring data, e.g. for logfile generation
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/10Mapping addresses of different types
    • H04L61/106Mapping addresses of different types across networks, e.g. mapping telephone numbers to data network addresses
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/55Push-based network services
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols

Definitions

  • the present invention relates to the field of communications technologies, and in particular, to a multi-service shared long connection system, an apparatus, and a terminal.
  • IP Internet Protocol
  • Most terminal devices such as mobile phones, computers, and smart TVs, use intranet IP under the network operator gateway. For example, they all use IPV4 and do not have independent public IP.
  • network operators will recycle addresses that are not used for a long time, and such recycling will not be notified. Therefore, under normal circumstances, the client existing in the terminal and the server existing in the network operator cannot know that the connection established between them has been reclaimed if no communication attempt is made.
  • the client in various terminals sends a request for obtaining information to the server of the network operator unilaterally, which can no longer meet the requirement that the app of the terminal can obtain information in time.
  • a news app on a terminal when a major news occurs, the server can promptly push the message to the terminal to remind the user, and then the server of the network operator can immediately notify the client in the terminal, instead of It is limited to the client unilaterally requesting from the server.
  • a long connection In order to enable the client and server to notify each other in the current situation of the network, a long connection needs to be established.
  • one service uses a long connection, so that the long connection is not used efficiently, and the long connection is mostly idle. Because the heartbeat time cannot be aligned on the terminal, the CPU is often woken up and the power consumption is severe. And it is necessary to periodically send a heartbeat to maintain the survival of a long connection. Due to the variety of terminals, the network environment will be different. Some networks are good. It is possible to send a heartbeat in an hour. Some networks may take a minute to get a heartbeat. If you unify a heartbeat time, you must only take the lowest value, otherwise many can't live.
  • the main purpose of the present invention is to provide a multi-service shared long connection system, and a device and a terminal thereof, which are designed to realize a long connection channel for multi-service sharing and improve utilization of long connections.
  • the present invention provides a multi-service shared long connection method, including:
  • the long-connected client establishes a channel for transmitting data to the server of the long connection, and acquires the heartbeat time to maintain the survival of the long connection;
  • the long-connected server configures a unique service ID for each service according to the application request of each service, and sends the service ID to the long-connected client;
  • the long-connected client transmits the received service ID to the corresponding service client for reporting to the corresponding service server;
  • the long-connected server After receiving the service information pushed by the service server, the long-connected server sends the service information to the long-connected client through the channel according to the service ID;
  • the long-connected client pushes the business information to the business client according to the service ID.
  • the long-connected server configures a unique service ID for each service according to an application request of each service and sends the message to the long-connected client, including:
  • the long-connected server receives the service label application request sent by each service, and returns a service identifier to the service client according to the service label application request;
  • the long-connected client receives the service identifier sent by the service client, and establishes a unique feature value for identifying the terminal according to the attribute information of the terminal where the long-connected client is located, and transmits the service identifier and the feature value to the same Describe the server of the long connection;
  • the long-connected server generates a service ID corresponding to each service according to the service indication and the feature value, and sends the service ID to the persistently connected client.
  • the long-connected client establishes a channel for transmitting data to the server of the long connection, and acquiring the heartbeat time to maintain the survival of the long connection includes:
  • the initial heartbeat time calculates a second heartbeat time, and continues to send the second heartbeat time to the server of the long connection until the feedback of the server of the long connection is not received;
  • the time until the obtained fourth heartbeat time reaches a preset limit value or the heartbeat increase step size is zero, and the fourth heartbeat time at this time is taken as the survival heartbeat time for maintaining the long connection.
  • the heartbeat time is calculated according to the following formula:
  • the initial heartbeat increase step is calculated according to the following formula:
  • B 0 (f(n)-f(n-1))/2; where n ⁇ 1, B 0 represents the initial heartbeat increase step size, f(n) represents the second heartbeat time, f(n-1) Indicates the previous heartbeat time of the second heartbeat time;
  • B n (B n-1 )/2; wherein n ⁇ 1, B n represents a new heartbeat increase step size, and B n-1 represents a previous heartbeat increase step size of the new heartbeat increase step size;
  • the first heartbeat time is calculated according to the initial heartbeat time, and the first heartbeat time is transmitted to the server of the long connection, and when the feedback of the server of the long connection is received, the first The heartbeat time calculates the second heartbeat time as the new initial heartbeat time, and continues to send the second heartbeat time to the server of the long connection until the feedback of the server that does not receive the long connection includes:
  • the present invention further provides a multi-service shared long connection system, where the multi-service shared long connection system includes a long-connected client and a long-connected server, wherein
  • a long-connected client that establishes a channel for transmitting data to a server with a long connection, and Get the heartbeat time to maintain the survival of long connections;
  • the long-connected server is configured to configure a unique service ID for each service according to the application request of each service, and send the service ID to the long-connected client;
  • a long-connected client configured to transmit the received service ID to a corresponding service client for reporting to the corresponding service server;
  • the long-connected server is configured to send the service information to the long-connected client through the channel according to the service ID after receiving the service information pushed by the service server;
  • a long-connected client that pushes business information to the business client based on the business ID.
  • the long-connected server is further configured to receive a service indication application request sent by each service, and return a service indication to the service client according to the service indication application request;
  • the long-connected client is further configured to receive a service identifier sent by the service client, and establish a unique feature value for identifying the terminal according to the attribute information of the terminal where the long-connected client is located, and use the service identifier and the feature value. Delivered together to the server of the long connection;
  • the long-connected server is further configured to generate a service ID corresponding to each service according to the service indication and the feature value, and send the service ID to the persistently connected client.
  • the present invention further provides a method for acquiring a long-connected heartbeat time, including:
  • the initial heartbeat time calculates a second heartbeat time, and continues to send the second heartbeat time to the server of the long connection until the feedback of the server of the long connection is not received;
  • the time calculation calculates the fourth heartbeat time until the obtained fourth heartbeat time reaches a preset limit value or the heartbeat increase step size is zero, and the fourth heartbeat time at this time is used as the survival heartbeat time for maintaining the long connection.
  • the heartbeat time is calculated according to the following formula:
  • the initial heartbeat increase step is calculated according to the following formula:
  • B 0 (f(n)-f(n-1))/2; where n ⁇ 1, B 0 represents the initial heartbeat increase step size, f(n) represents the second heartbeat time, f(n-1) Indicates the previous heartbeat time of the second heartbeat time;
  • B n (B n-1 )/2; wherein n ⁇ 1, B n represents a new heartbeat increase step size, and B n-1 represents a previous heartbeat increase step size of the new heartbeat increase step size;
  • the calculating a first heartbeat time according to the initial heartbeat time, and transmitting the first heartbeat time to the server of the long connection, when receiving the feedback of the server of the long connection The first heartbeat time calculates the second heartbeat time as the new initial heartbeat time, and continues to send the second heartbeat time to the server of the long connection, until the feedback of the server that does not receive the long connection includes:
  • the present invention further provides a long-connected heartbeat time acquiring device, including:
  • An initial heartbeat time acquisition module configured to determine an initial heartbeat time according to a current network environment
  • a second heartbeat time acquisition module configured to calculate a first heartbeat time according to the initial heartbeat time, and transmit the first heartbeat time to the server of the long connection, and receive the long-connected service
  • the second heartbeat time is calculated by using the first heartbeat time as the new initial heartbeat time, and the second heartbeat time is continuously sent to the server of the long connection until the feedback of the server of the long connection is not received;
  • a transmitting module configured to: when the feedback of the server of the long connection is not received, transmit the initial heartbeat time to the server of the long connection, where the server that receives the long connection is for an initial heartbeat time Sending, the previous heartbeat time of the second heartbeat time is transmitted to the server of the long connection;
  • An initial heartbeat increase step size obtaining module configured to calculate an initial heartbeat increase step size according to the second heartbeat time and the previous heartbeat time after receiving the feedback of the long-connected server;
  • a fourth heartbeat time acquisition module configured to calculate a third heartbeat time according to the initial heartbeat increase step size and the second heartbeat time, calculate a new heartbeat increase step size according to the initial heartbeat increase step size, and increase the step size according to the new heartbeat
  • the third heartbeat time is calculated to obtain the fourth heartbeat time until the obtained fourth heartbeat time reaches a preset limit value or the heartbeat increase step is zero, and the fourth heartbeat time at this time is taken as the survival heartbeat time for maintaining the long connection.
  • the heartbeat time is calculated according to the following formula:
  • the initial heartbeat increase step is calculated according to the following formula:
  • B 0 (f(n)-f(n-1))/2; where n ⁇ 1, B 0 represents the initial heartbeat increase step size, f(n) represents the second heartbeat time, f(n-1) Indicates the previous heartbeat time of the second heartbeat time;
  • B n (B n-1 )/2; wherein n ⁇ 1, B n represents a new heartbeat increase step size, and B n-1 represents a previous heartbeat increase step size of the new heartbeat increase step size;
  • the second heartbeat time obtaining module is further configured to: when the first heartbeat time or the second heartbeat time is transmitted to the server of the long connection, the preset number of transmissions does not satisfy the server that receives the long connection The preset number of times of feedback determines the feedback of the server that has not received the long connection.
  • the present invention also provides a terminal including the long-connected heartbeat time acquiring means of the above structure.
  • the long-connected server configures a unique service ID for each service according to the application request of each service, and sends the service ID to the long-connected client.
  • the long-connected client transmits the received service ID to the corresponding service client for reporting to the corresponding service server.
  • the long-connected server After receiving the service information pushed by the service server, the long-connected server sends the service information to the long-connected client through the channel according to the service ID, and the long-connected client pushes the service information to the service client according to the service ID. .
  • a long connection channel is shared by multiple services, and the utilization of long connections is improved.
  • FIG. 1 is a schematic flowchart of an embodiment of a multi-service shared long connection method according to the present invention
  • FIG. 2 is a schematic diagram of a refinement process in which a long-connected server configures a unique service ID for each service and sends it to a long-connected client according to an application request of each service in the multi-service shared long connection method of the present invention
  • FIG. 3 is a schematic diagram of a refinement process for a long-connected client to establish a channel for transmitting data to a long-connected server, and obtaining a heartbeat time to maintain a long connection, in the multi-service shared long connection method of the present invention
  • FIG. 4 is a schematic flowchart of an embodiment of a method for acquiring a heartbeat time of a long connection according to the present invention
  • FIG. 5 is a schematic diagram of functional modules of an embodiment of a long-connected heartbeat time acquiring apparatus according to the present invention.
  • the multi-service shared long connection method of this embodiment includes:
  • Step S10 The long-connected client establishes a channel for transmitting data to the server of the long connection, and acquires a heartbeat time to maintain the survival of the long connection;
  • a stable and adaptive long connection can be created from the system level of the terminal.
  • the long-connected client in the terminal needs to establish a channel for transmitting data according to the network protocol with the server of the long connection, and the type of the terminal can be set according to actual needs, for example, a mobile phone, a computer, a smart TV, and the like.
  • the client that is long-connected first establishes a channel for transmitting data with the server that is connected to the long connection, for example, establishing a TCPSocket.
  • the long-connected client sends an online command to the long-connected server according to the message protocol, and waits for the server that receives the long connection to issue the command.
  • the message protocol may be a pre-set network protocol for transmitting data. For example, a client with a long connection sends a "1" as an online command, a "2" is an offline command, and a command can return a "3" for a long-connected server. "" indicates that the client has received a long connection.
  • the long-connected client When the long-connected client receives a reply from the server with a long connection, it indicates that the long-connected server has received the online command sent by the long-connected client, and the message is parsed according to the message protocol to obtain the transmitted message content. And according to the content prompts for corresponding processing. Then the long-connected client obtains the heartbeat time, transmits the obtained current heartbeat time to the long-connected server, and waits for the server to return the heartbeat time. After receiving the message returned by the server with a long connection, the client that repeats the long connection resolves the message according to the message protocol and obtains the current heartbeat time and transmits it to the server of the long connection until the optimal heartbeat time is obtained.
  • the heartbeat time maintains the survival of long connections, ie, maintains the stability of the channel. This long connection is established for sharing by multiple services.
  • Step S20 The long-connected server configures a unique service ID for each service according to the application request of each service, and sends the service ID to the persistently connected client.
  • each service requests the long-connected server to obtain the respective number, that is, each service is connected to the long-connected server.
  • the long-connected server configures a unique service ID for each service after receiving the request, and sends the configured service ID to the long-connected client for the long-connected client to conduct the service.
  • the ID is delivered to the business client.
  • Step S30 The long-connected client transmits the received service ID to the corresponding service customer.
  • the client is for reporting to the corresponding service server;
  • the long-connected client After receiving the service IDs sent by the server connected by the long connection, the long-connected client transmits each service ID to the corresponding service client. After receiving the service ID, each service client reports the service ID to its corresponding service server.
  • Step S40 After receiving the service information pushed by the service server, the long-connected server sends the service information to the long-connected client through the channel according to the service ID.
  • the service information to be pushed is sent to the server of the long connection together with the service ID.
  • the long-connected server finds the terminal where the long-connected client is located according to the service ID, and establishes the long-connected server and the long-connected client through the above-mentioned established server. A channel for data transmission, which sends service information to a long-connected client.
  • Step S50 The long-connected client pushes the service information to the service client according to the service ID.
  • the long-connected client After receiving the service ID and service information sent by the server connected by the long connection, the long-connected client finds the corresponding service according to the service ID, and pushes the service information to the service client.
  • the long-connected client on the smart TV creates a channel that uses the network protocol to transfer data between the long-connected server, that is, creates a long connection.
  • the long-connected client can be named com.tianci.push.
  • the three services of the smart TV upgrade service, the video push service, and the module update service respectively apply for a separate service mark to the established long-connected server.
  • the upgrade service, the video push service, and the module update service use android broadcast to send the package name (ie, the key information of the service) and the corresponding service identifier to com.tianci.push.
  • the com.tianci.push After receiving the self-package name and the corresponding service identifier transmitted by the three services, the com.tianci.push associates the three service identifiers with the corresponding package names in the database.
  • Com.tianci.push constructs a feature value of a long connection corresponding to the smart TV according to the information of the smart TV, and the feature value is unique, and the feature value may include a version number, a physical address, and the like of the smart TV.
  • Com.tianci.push sends the eigenvalue and the three service identifiers to the long-connected server through the long-connected data transmission channel, and the long-connected server generates the trait according to the eigenvalue and the three service labels.
  • the service ID corresponding to each service and return the service ID and the corresponding service identifier to com.tianci.push.
  • Com.tianci.push updates the database according to the service indications of the three services, that is, stores the service identifiers of the three services, their respective service IDs, and their respective package names in the database. At the same time, find the respective package names of the three services, and send the three service IDs to the corresponding services.
  • the video and video push service reports the service ID to the server of the video push service.
  • the server of the video push service sends the service ID and the video push service information to the long-connected server.
  • the long-connected server finds the smart TV device according to the service ID, and sends the service ID and the video push service information to the com.tianic.push located on the smart TV.
  • com.tianci.push finds the package name of the video push service, and assigns the video push service information to the client of the video push service.
  • the client of the video push service parses and processes the received information according to its own protocol.
  • the long-connected server configures a unique service ID for each service according to the application request of each service, and sends the service ID to the long-connected client.
  • the long-connected client transmits the received service ID to the corresponding service client for reporting to the corresponding service server.
  • the long-connected server After receiving the service information pushed by the service server, the long-connected server sends the service information to the long-connected client through the channel according to the service ID, and the long-connected client pushes the service information to the service client according to the service ID. .
  • a long connection channel is shared by multiple services, and the utilization of long connections is improved.
  • the foregoing step S20 may include:
  • Step S21 The server that is connected to the long end receives the service label application request sent by each service, and returns a service identifier to the service client according to the service label application request;
  • the long-connected server configures a unique service ID for each service according to the application request of each service. Specifically, each service first applies for a service identifier to the long-connected server. The long-connected server returns a service identifier to the corresponding service client according to the service label application request sent by each service. Then, each service client transmits the respective service identifier to the long-connected client on the terminal. Understandably, the multi-service is two or More than two services, of course, if the single connection uses the long connection, it is not necessary to apply for a service indication to the long-connected server.
  • Step S22 The long-connected client receives the service identifier sent by the service client, and establishes a unique feature value for identifying the terminal according to the attribute information of the terminal where the long-connected client is located, and the service identifier and the feature value are together. Transmitting to the server of the long connection;
  • the long-connected client After receiving the service identifier, the long-connected client associates each service identifier with the key information of the corresponding service as a pair of key values in the database, so as to obtain the key information of the service according to the service indication.
  • the key information of the business can include the name of the business.
  • the attribute information of the terminal is obtained as the unique feature value of the terminal according to the terminal where the client is connected, for example, the feature value may include the physical address, version number, etc. of the terminal where the connected client is located. .
  • the characteristic values of the service identifiers and the long connections are transmitted together to the server of the long connection, so that the long-connected server can generate the service ID corresponding to each service according to the characteristic values of the service identifiers and the long connections.
  • Step S23 The long-connected server generates a service ID corresponding to each service according to the service indication and the feature value, and sends the service ID to the persistently connected client.
  • the server that is connected to the long-term connection After receiving the characteristic values of the service identifiers and the long connections, the server that is connected to the long-term connection checks whether the service labels are correct according to the respective service identifiers applied by the long-connected server to each service, that is, whether the service is forward-connected. The service sign of the server application. If it is correct, the long-connected server generates a unique service ID corresponding to each service according to the feature value of the long connection and each service identifier, and returns each service ID and corresponding service identifier to the long-connected client. After receiving the service IDs and the corresponding service identifiers, the long-connected client associates the service IDs of each service with the service IDs, and stores the service IDs, service identifiers, and business key information of each service in the database. The database for updating the key information of each of the indications and the corresponding service is updated.
  • the foregoing step S10 may include:
  • Step S11 Determine an initial heartbeat time according to a current network environment.
  • the long-connected client After the long-connected client establishes a connection with the long-connected server, the long-connected client sends its own related information to the long-connected server, and the long-connected server identifies the long-connected client.
  • the terminal in order to complete the process of initializing the server on the long connection.
  • the long-connected client Since the initial heartbeat time is related to the network environment, the long-connected client initializes the initial heartbeat time according to the current network environment in which the terminal is located by detecting the current network environment.
  • the default initial value can be set to 10 to 50 seconds, or can be flexibly set according to the specific situation.
  • Step S12 Calculate a first heartbeat time according to the initial heartbeat time, and transmit the first heartbeat time to the server of the long connection, and receive the feedback of the server that is connected to the first heartbeat time. Calculating the second heartbeat time as the new initial heartbeat time, and continuing to send the second heartbeat time to the server of the long connection until the feedback of the server of the long connection is not received;
  • the long-connected client obtains the first heartbeat time
  • the first heartbeat time is transmitted to the long-connected server.
  • the step increment is repeated to calculate the second heartbeat time according to the formula.
  • the obtained second heartbeat time is continuously sent to the server of the long connection until the feedback of the server of the long connection is not received, and the calculation of the second heartbeat time by the above formula is stopped.
  • the feedback of the server that is connected to the long connection may be the heartbeat time sent by the client that returns the long connection, or may return the specified information according to a preset protocol.
  • the second heartbeat time is repeatedly calculated by the above formula, so that in the process of finding the optimal heartbeat time, when the heartbeat time increases rapidly, the critical value of the heartbeat time is found as few times as possible.
  • the long-connected client may transmit the first heartbeat time or the second heartbeat time to the server of the long connection multiple times.
  • the preset number of transmissions of transmitting the first heartbeat time or the second heartbeat time to the server of the long connection does not satisfy the preset number of times of receiving the server feedback of the long connection, it is determined that the feedback of the server of the long connection is not received.
  • the preset number of transmissions and the preset number of times can be flexibly set according to specific conditions. For example, a long-connected client transmits the first heartbeat time 3 times to a long-connected server. If the server receives a long-connected server feedback 3 times, the long-connected client will be the first. When a heartbeat time is sent to the server of the long connection, the feedback of the server of the long connection can be successfully received.
  • Step S13 When the feedback of the long-connected server is not received, the initial heartbeat time is Transmitting to the server of the long connection, when receiving the feedback of the server of the long connection for the initial heartbeat time, transmitting the previous heartbeat time of the second heartbeat time to the server of the long connection;
  • the initial heartbeat time is used to try, that is, the long-connected client transmits the initial heartbeat time to the long-connected server to detect Whether the long-connected client will receive the long-connected server returns the initial heartbeat time.
  • the long-connected client may transmit the initial heartbeat time to the long-connected server multiple times, and perform corresponding processing according to whether the preset number of feedbacks of the server that receives the long-connection is received on time. For example, a client with a long connection can transmit the initial heartbeat time 5 times to the server of the long connection. When the feedback of the server that receives the long connection on time is 5 or 4 times, the server that successfully receives the long connection is successfully received. Feedback, otherwise it fails.
  • the process proceeds to step 11 to re-initialize the heartbeat time.
  • the previous heartbeat time of the second heartbeat time is used to try, that is, the previous heartbeat time of the second heartbeat time is transmitted to the long-connected service. end.
  • the second heartbeat time is the last heartbeat time that is sent when the server that receives the long connection does not receive feedback for the second heartbeat time.
  • the number of times the previous heartbeat time is transmitted can be flexibly set according to the specific situation, and corresponding processing is performed according to whether the preset number of feedbacks of the server that receives the long connection on time is satisfied.
  • Step S14 After receiving the feedback of the server that is connected to the long connection, calculate an initial heartbeat increase step according to the second heartbeat time and the previous heartbeat time;
  • the process proceeds to step 11 to re-initialize the heartbeat time.
  • B 0 represents an initial heart rate increase in step length
  • f (n) represents a second heartbeat time
  • f (n-1) represents a second heartbeat time before the time of a heartbeat.
  • Step S15 Calculate a third heartbeat time according to the initial heartbeat increase step size and the second heartbeat time, calculate a new heartbeat increase step size according to the initial heartbeat increase step size, and calculate according to the new heartbeat increase step size and the third heartbeat time.
  • the fourth heartbeat time is until the obtained fourth heartbeat time reaches a preset limit value or the heartbeat increase step is zero, and the fourth heartbeat time at this time is used as the long-term connection. Survival heartbeat time.
  • B n represents a new heartbeat increase step size
  • B n-1 represents a previous heartbeat increase step size of the new heartbeat increase step.
  • the optimal value can be quickly found.
  • the long-connected client sends the obtained third heartbeat time to the server of the long connection, and when receiving the feedback of the server with the long connection, increments n by 1 step, and calculates the fourth heartbeat according to the formula. time.
  • the process proceeds to step S13, and the initial heartbeat time is retransmitted to the server of the long connection to try.
  • the long-connected client then sends the obtained fourth heartbeat time to the long-connected server, and when receiving the feedback of the long-connected server for the fourth heartbeat time, increments n to continue calculating the fourth heartbeat time until it is obtained.
  • the fourth heartbeat time reaches a preset limit value or the heartbeat increase step size is zero, and the fourth heartbeat time at this time is taken as the survival heartbeat time for maintaining the long connection.
  • the multi-service shared long connection system includes a long-connected client and a long-connected server.
  • a long-connected client that establishes a channel for transmitting data to a long-connected server and acquires heartbeat time to maintain the survival of a long connection
  • a stable and adaptive long connection can be created from the system level of the terminal.
  • the long-connected client in the terminal needs to establish a channel for transmitting data according to the network protocol with the server of the long connection, and the type of the terminal can be set according to actual needs, for example, a mobile phone, a computer, a smart TV, and the like.
  • the client that is long-connected first establishes a channel for transmitting data with the server that is connected to the long connection, for example, establishing a TCPSocket.
  • the long-connected client sends an online command to the long-connected server according to the message protocol, and waits for the server that receives the long connection to issue the command.
  • the message protocol may be a pre-set network protocol for transmitting data. For example, a client with a long connection sends a "1" as an online command, a "2" is an offline command, and a command can return a "3" for a long-connected server. "" indicates that the client has received a long connection.
  • a long-connected client When a long-connected client receives a reply from a long-connected server, it indicates that the long-connected server has received a long connection.
  • the online command sent by the client at this time, the message will be parsed according to the message protocol to obtain the content of the transmitted message, and corresponding processing is performed according to the content prompt.
  • the long-connected client obtains the heartbeat time, transmits the obtained current heartbeat time to the long-connected server, and waits for the server to return the heartbeat time.
  • the client that repeats the long connection resolves the message according to the message protocol and obtains the current heartbeat time and transmits it to the server of the long connection until the optimal heartbeat time is obtained.
  • the heartbeat time maintains the survival of long connections, ie, maintains the stability of the channel. This long connection is established for sharing by multiple services.
  • the long-connected server is configured to configure a unique service ID for each service according to the application request of each service, and send the service ID to the long-connected client;
  • each service requests the long-connected server to obtain the respective number, that is, each service is connected to the long-connected server.
  • the long-connected server configures a unique service ID for each service after receiving the request, and sends the configured service ID to the long-connected client for the long-connected client to conduct the service.
  • the ID is delivered to the business client.
  • a long-connected client configured to transmit the received service ID to a corresponding service client for reporting to the corresponding service server;
  • the long-connected client After receiving the service IDs sent by the server connected by the long connection, the long-connected client transmits each service ID to the corresponding service client. After receiving the service ID, each service client reports the service ID to its corresponding service server.
  • the long-connected server is configured to send the service information to the long-connected client through the channel according to the service ID after receiving the service information pushed by the service server;
  • the service information to be pushed is sent to the server of the long connection together with the service ID.
  • the long-connected server finds the terminal where the long-connected client is located according to the service ID, and establishes the long-connected server and the long-connected client through the above-mentioned established server. A channel for data transmission, which sends service information to a long-connected client.
  • a long-connected client that pushes business information to the business client based on the business ID.
  • the long-connected client After receiving the service ID and service information sent by the server connected by the long connection, the long-connected client finds the corresponding service according to the service ID, and pushes the service information to the service client.
  • the long-connected client on the smart TV creates a channel that uses the network protocol to transfer data between the long-connected server, that is, creates a long connection.
  • the long-connected client can be named com.tianci.push.
  • the three services of the smart TV upgrade service, the video push service, and the module update service respectively apply for a separate service mark to the established long-connected server.
  • the upgrade service, the video push service, and the module update service use android broadcast to send the package name (ie, the key information of the service) and the corresponding service identifier to com.tianci.push.
  • the com.tianci.push After receiving the self-package name and the corresponding service identifier transmitted by the three services, the com.tianci.push associates the three service identifiers with the corresponding package names in the database.
  • Com.tianci.push constructs a feature value of a long connection corresponding to the smart TV according to the information of the smart TV, and the feature value is unique, and the feature value may include a version number, a physical address, and the like of the smart TV.
  • Com.tianci.push sends the feature value and the three service identifiers to the long-connected server through the long-connected data transmission channel, and the long-connected server generates the service corresponding to each service according to the feature value and the three service indicators. ID, and return the business ID and corresponding business identifier to com.tianci.push.
  • Com.tianci.push updates the database according to the service indications of the three services, that is, stores the service identifiers of the three services, their respective service IDs, and their respective package names in the database. At the same time, find the respective package names of the three services, and send the three service IDs to the corresponding services.
  • the video and video push service reports the service ID to the server of the video push service.
  • the server of the video push service sends the service ID and the video push service information to the long-connected server.
  • the long-connected server finds the smart TV device according to the service ID, and sends the service ID and the video push service information to the com.tianic.push located on the smart TV.
  • com.tianci.push finds the package name of the video push service, and assigns the video push service information to the client of the video push service.
  • the client of the video push service parses and processes the received information according to its own protocol.
  • the long-connected server configures a unique service ID for each service according to the application request of each service, and the service is The ID is sent to the client of the long connection.
  • the long-connected client transmits the received service ID to the corresponding service client for reporting to the corresponding service server.
  • the long-connected server After receiving the service information pushed by the service server, the long-connected server sends the service information to the long-connected client through the channel according to the service ID, and the long-connected client pushes the service information to the service client according to the service ID. .
  • a long connection channel is shared by multiple services, and the utilization of long connections is improved.
  • the long-connected server is further configured to receive a service label application request sent by each service, and return a service identifier to the service client according to the service label application request;
  • the long-connected server configures a unique service ID for each service according to the application request of each service. Specifically, each service first applies for a service identifier to the long-connected server. The long-connected server returns a service identifier to the corresponding service client according to the service label application request sent by each service. Then, each service client transmits the respective service identifier to the long-connected client on the terminal. It can be understood that the multi-service is two or more services. Of course, if the single service uses the long connection, it is not required to apply for the service indication to the long-connected server.
  • the long-connected client is further configured to receive a service identifier sent by the service client, and establish a unique feature value for identifying the terminal according to the attribute information of the terminal where the long-connected client is located, and use the service identifier and the feature value. Delivered together to the server of the long connection;
  • the long-connected client After receiving the service identifier, the long-connected client associates each service identifier with the key information of the corresponding service as a pair of key values in the database, so as to obtain the key information of the service according to the service indication.
  • the key information of the business can include the name of the business.
  • the attribute information of the terminal is obtained as the unique feature value of the terminal according to the terminal where the client is connected, for example, the feature value may include the physical address, version number, etc. of the terminal where the connected client is located. .
  • the characteristic values of the service identifiers and the long connections are transmitted together to the server of the long connection, so that the long-connected server can generate the service ID corresponding to each service according to the characteristic values of the service identifiers and the long connections.
  • the long-connected server is further configured to generate a service ID corresponding to each service according to the service indication and the feature value, and send the service ID to the persistently connected client.
  • the long-connected server After the long-connected server receives the characteristic values of each service indicator and long connection, according to each industry The respective service identifiers of the long-connected server applications are checked, and whether the service identifiers are correct, that is, whether the service identifiers previously applied to the long-connected server are applied. If it is correct, the long-connected server generates a unique service ID corresponding to each service according to the feature value of the long connection and each service identifier, and returns each service ID and corresponding service identifier to the long-connected client. After receiving the service IDs and the corresponding service identifiers, the long-connected client associates the service IDs of each service with the service IDs, and stores the service IDs, service identifiers, and business key information of each service in the database. The database for updating the key information of each of the indications and the corresponding service is updated.
  • the long-connected heartbeat time acquisition method of this embodiment includes:
  • Step S1 determining an initial heartbeat time according to a current network environment
  • the long-connected client After the long-connected client establishes a connection with the long-connected server, the long-connected client sends its own related information to the long-connected server, and the long-connected server identifies the long-connected client to complete the long The process of connecting the server to the line initialization.
  • the long-connected client Since the initial heartbeat time is related to the network environment, the long-connected client initializes the initial heartbeat time according to the current network environment in which the terminal is located by detecting the current network environment.
  • the default initial value can be set to 10 to 50 seconds, or can be flexibly set according to the specific situation.
  • Step S2 Calculate a first heartbeat time according to the initial heartbeat time, and transmit the first heartbeat time to the server of the long connection, and receive the feedback of the server that is connected to the first heartbeat time. Calculating the second heartbeat time as the new initial heartbeat time, and continuing to send the second heartbeat time to the server of the long connection until the feedback of the server of the long connection is not received;
  • the long-connected client obtains the first heartbeat time
  • the first heartbeat time is transmitted to the long-connected server.
  • the server When receiving the feedback of the server with the long connection, it indicates that the first heartbeat time is successful for maintaining the survival of the long connection, and then calculating the second heartbeat time with the first heartbeat time as the new initial heartbeat time, that is, n is 1
  • the step increment is repeated to calculate the second heartbeat time according to the formula. Will get the second heartbeat time to continue
  • the server is sent to the long-connected server until the feedback of the server with the long connection is not received, and the second heartbeat time is stopped by the above formula.
  • the feedback of the server that is connected to the long connection may be the heartbeat time sent by the client that returns the long connection, or may return the specified information according to a preset protocol.
  • the second heartbeat time is repeatedly calculated by the above formula, so that in the process of finding the optimal heartbeat time, when the heartbeat time increases rapidly, the critical value of the heartbeat time is found as few times as possible.
  • the long-connected client may transmit the first heartbeat time or the second heartbeat time to the server of the long connection multiple times.
  • the preset number of transmissions of transmitting the first heartbeat time or the second heartbeat time to the server of the long connection does not satisfy the preset number of times of receiving the server feedback of the long connection, it is determined that the feedback of the server of the long connection is not received.
  • the preset number of transmissions and the preset number of times can be flexibly set according to specific conditions. For example, a long-connected client transmits the first heartbeat time 3 times to a long-connected server. If the server receives a long-connected server feedback 3 times, the long-connected client will be the first. When a heartbeat time is sent to the server of the long connection, the feedback of the server of the long connection can be successfully received.
  • Step S3 When the feedback of the long-connected server is not received, the initial heartbeat time is transmitted to the server of the long connection, and when the server of the long connection receives the feedback for the initial heartbeat time Transmitting a previous heartbeat time of the second heartbeat time to the server of the long connection;
  • the initial heartbeat time is used to try, that is, the long-connected client transmits the initial heartbeat time to the long-connected server to detect Whether the long-connected client will receive the long-connected server returns the initial heartbeat time.
  • the long-connected client may transmit the initial heartbeat time to the long-connected server multiple times, and perform corresponding processing according to whether the preset number of feedbacks of the server that receives the long-connection is received on time. For example, a client with a long connection can transmit the initial heartbeat time 5 times to the server of the long connection. When the feedback of the server that receives the long connection on time is 5 or 4 times, the server that successfully receives the long connection is successfully received. Feedback, otherwise it fails.
  • the process proceeds to step 1 to re-initialize the heartbeat time.
  • the previous heartbeat time of the second heartbeat time is used to try, that is, the previous heartbeat time of the second heartbeat time is transmitted to the long-connected service. end.
  • the second heartbeat time is the inverse of the second heartbeat time of the server that does not receive the long connection.
  • the second heartbeat time that was last sent. The number of times the previous heartbeat time is transmitted can be flexibly set according to the specific situation, and corresponding processing is performed according to whether the preset number of feedbacks of the server that receives the long connection on time is satisfied.
  • Step S4 After receiving the feedback of the server of the long connection, calculate an initial heartbeat increase step according to the second heartbeat time and the previous heartbeat time;
  • the process proceeds to step 1 to re-initialize the heartbeat time.
  • B 0 represents an initial heart rate increase in step length
  • f (n) represents a second heartbeat time
  • f (n-1) represents a second heartbeat time before the time of a heartbeat.
  • Step S5 Calculate a third heartbeat time according to the initial heartbeat increase step size and the second heartbeat time, calculate a new heartbeat increase step size according to the initial heartbeat increase step size, and calculate according to the new heartbeat increase step size and the third heartbeat time.
  • the fourth heartbeat time is until the obtained fourth heartbeat time reaches a preset limit value or the heartbeat increase step size is zero, and the fourth heartbeat time at this time is taken as the survival heartbeat time for maintaining the long connection.
  • B n represents a new heartbeat increase step size
  • B n-1 represents a previous heartbeat increase step size of the new heartbeat increase step.
  • the optimal value can be quickly found.
  • the long-connected client sends the obtained third heartbeat time to the server of the long connection, and when receiving the feedback of the server with the long connection, increments n by 1 step, and calculates the fourth heartbeat according to the formula. time.
  • the process proceeds to step S3, and the initial heartbeat time is retransmitted to the server of the long connection to try.
  • the long-connected client then sends the obtained fourth heartbeat time to the long-connected server, and when receiving the feedback of the long-connected server for the fourth heartbeat time, increments n to continue calculating the fourth heartbeat time until it is obtained.
  • the fourth heartbeat time reaches a preset limit value or the heartbeat increase step size is zero, and the fourth heartbeat time at this time is taken as the survival heartbeat time for maintaining the long connection.
  • the long-connected heartbeat time acquisition device of this embodiment includes:
  • the initial heartbeat time acquisition module 100 is configured to determine an initial heartbeat time according to a current network environment
  • the long-connected client After the long-connected client establishes a connection with the long-connected server, the long-connected client sends its own related information to the long-connected server, and the long-connected server identifies the long-connected client to complete the long The process of connecting the server to the line initialization.
  • the long-connected client Since the initial heartbeat time is related to the network environment, the long-connected client initializes the initial heartbeat time according to the current network environment in which the terminal is located by detecting the current network environment.
  • the default initial value can be set to 10 to 50 seconds, or can be flexibly set according to the specific situation.
  • the second heartbeat time acquisition module 200 is configured to calculate a first heartbeat time according to the initial heartbeat time, and transmit the first heartbeat time to the server of the long connection, and receive feedback of the server of the long connection Calculating the second heartbeat time with the first heartbeat time as the new initial heartbeat time, and continuing to send the second heartbeat time to the server of the long connection until the feedback of the server of the long connection is not received;
  • the long-connected client obtains the first heartbeat time, the first heartbeat time is transmitted to the long-connected server.
  • the step increment is repeated to calculate the second heartbeat time according to the formula.
  • the obtained second heartbeat time is continuously sent to the server of the long connection until the feedback of the server of the long connection is not received, and the calculation of the second heartbeat time by the above formula is stopped.
  • the feedback of the server that is connected to the long connection may be the heartbeat time sent by the client that returns the long connection, or may return the specified information according to a preset protocol.
  • the second heartbeat time is repeatedly calculated by the above formula, so that in the process of finding the optimal heartbeat time, when the heartbeat time increases rapidly, the critical value of the heartbeat time is found as few times as possible.
  • the long-connected client can The first heartbeat time or the second heartbeat time is transmitted to the server of the long connection multiple times.
  • the preset number of transmissions of transmitting the first heartbeat time or the second heartbeat time to the server of the long connection does not satisfy the preset number of times of receiving the server feedback of the long connection, it is determined that the feedback of the server of the long connection is not received.
  • the preset number of transmissions and the preset number of times can be flexibly set according to specific conditions. For example, a long-connected client transmits the first heartbeat time 3 times to a long-connected server. If the server receives a long-connected server feedback 3 times, the long-connected client will be the first. When a heartbeat time is sent to the server of the long connection, the feedback of the server of the long connection can be successfully received.
  • the transmitting module 300 is configured to transmit the initial heartbeat time to the server of the long connection when the feedback of the server of the long connection is not received, and the initial heartbeat time of the server that receives the long connection The feedback, transmitting the previous heartbeat time of the second heartbeat time to the server of the long connection;
  • the initial heartbeat time is used to try, that is, the long-connected client calls the transmitting module 300 to transmit the initial heartbeat time to the long-connected service. End, to detect whether the long-connected client will receive the long-connected server to return the initial heartbeat time.
  • the long-connected client may transmit the initial heartbeat time to the long-connected server multiple times, and perform corresponding processing according to whether the preset number of feedbacks of the server that receives the long-connection is received on time. For example, a client with a long connection can transmit the initial heartbeat time 5 times to the server of the long connection. When the feedback of the server that receives the long connection on time is 5 or 4 times, the server that successfully receives the long connection is successfully received. Feedback, otherwise it fails.
  • the heartbeat time is re-initialized.
  • the previous heartbeat time of the second heartbeat time is used, that is, the transmission module 300 transmits the previous heartbeat time of the second heartbeat time.
  • the second heartbeat time is the last heartbeat time that is sent when the server that receives the long connection does not receive feedback for the second heartbeat time.
  • the number of times the previous heartbeat time is transmitted can be flexibly set according to the specific situation, and corresponding processing is performed according to whether the preset number of feedbacks of the server that receives the long connection on time is satisfied.
  • the initial heartbeat increase step size obtaining module 400 is configured to calculate an initial heartbeat increase step size according to the second heartbeat time and the previous heartbeat time after receiving the feedback of the long-connected server;
  • the heartbeat time is re-initialized.
  • B 0 represents an initial heart rate increase in step length
  • f (n) represents a second heartbeat time
  • f (n-1) represents a second heartbeat time before the time of a heartbeat.
  • the fourth heartbeat time acquisition module 500 is configured to calculate a third heartbeat time according to the initial heartbeat increase step size and the second heartbeat time, calculate a new heartbeat increase step size according to the initial heartbeat increase step size, and increase the step size according to the new heartbeat Calculating the fourth heartbeat time with the third heartbeat time until the obtained fourth heartbeat time reaches a preset limit value or the heartbeat increase step is zero, and the fourth heartbeat time at this time is used as the survival heartbeat time for maintaining the long connection. .
  • the initial heartbeat time is resently sent to the server of the long connection to try.
  • the long-connected client then sends the obtained fourth heartbeat time to the long-connected server, and when receiving the feedback of the long-connected server for the fourth heartbeat time, increments n to continue calculating the fourth heartbeat time until it is obtained.
  • the fourth heartbeat time reaches a preset limit value or the heartbeat increase step size is zero, and the fourth heartbeat time at this time is taken as the survival heartbeat time for maintaining the long connection.
  • the present invention provides a terminal that includes the long-connected heartbeat time acquisition device of the above structure, that is, includes an initial heartbeat time acquisition module 100, a second heartbeat time acquisition module 200, a transmission module 300, and an initial heartbeat increase step size.
  • the obtaining module 400 and the fourth heartbeat time obtaining module 500 are the terminals.
  • the terminal can be a mobile phone, a computer, a smart TV, or the like.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Health & Medical Sciences (AREA)
  • Cardiology (AREA)
  • General Health & Medical Sciences (AREA)
  • Data Mining & Analysis (AREA)
  • Telephonic Communication Services (AREA)
  • Computer And Data Communications (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

本发明公开了一种多业务共享长连接方法,包括:长连接的客户端建立用于传输数据至长连接的服务端的通道,并获取心跳时间维持长连接的存活;长连接的服务端根据各业务的申请请求为各业务配置唯一的业务ID,并将所述业务ID发送至长连接的客户端;长连接的客户端将接收到的所述业务ID传送至对应的业务客户端,以供其上报至与其对应的业务服务端;长连接的服务端在接收到业务服务端推送的业务信息后,根据业务ID通过所述通道将业务信息发送至长连接的客户端;长连接的客户端根据业务ID将业务信息推送至业务客户端。本发明还公开了一种多业务共享长连接系统及其装置、终端。本发明实现了多业务共享一条长连接,提高了长连接的利用率。

Description

多业务共享长连接方法、系统及其装置、终端 技术领域
本发明涉及通信技术领域,尤其涉及一种多业务共享长连接系统、及其装置、终端。
背景技术
现在绝大多数的终端设备,如手机、电脑、智能电视等终端,都是使用网络运营商网关下面的内网IP,例如,都是使用IPV4,并没有独立的公网IP。网络运营商为了提高地址利用率,会把长期不使用的地址进行回收,而这种回收是不会进行通知的。所以正常情况下,存在于终端的客户端和存在于网络运营商的服务端如果不进行再次通讯尝试,是没法知道它们之间建立的连接已经被回收了。
随着时代的发展,各种终端中的客户端单方面向网络运营商的服务端发送获取信息的请求,不再能满足终端的app能够及时获取信息的需求。例如,一个终端上的新闻app,在发生重大新闻的时候,服务端能够及时将消息推送至终端以提醒用户,这时就需要网络运营商的服务端能够马上通知终端中的客户端,而不再局限于客户端单方面向服务端请求。
而为了使得在网络现状下客服端和服务端能够进行相互通知,需要建立长连接。现有的长连接方案中,一条业务使用一条长连接,使得长连接的利用率不高,长连接绝大多数都是出于空闲状态。在终端上由于心跳时间无法对齐,导致CPU经常被唤醒,耗电严重。而且需要定时发送一个心跳维持长连接的存活。由于终端多种多样,所处的网络环境也会不同,有的网络好,可能一个小时发送一个心跳就可以了,有的网络可能需要一分钟就需要一个心跳。如果统一一个发送心跳时间,必然只能取其最低值,不然很多没法活。
发明内容
本发明的主要目的在于提供一种多业务共享长连接系统、及其装置、终端,旨在实现多业务共享一条长连接通道,提高长连接的利用率。
为实现上述目的,本发明提供了一种多业务共享长连接方法,包括:
长连接的客户端建立用于传输数据至长连接的服务端的通道,并获取心跳时间维持长连接的存活;
长连接的服务端根据各业务的申请请求为各业务配置唯一的业务ID,并将所述业务ID发送至长连接的客户端;
长连接的客户端将接收到的所述业务ID传送至对应的业务客户端,以供其上报至与其对应的业务服务端;
长连接的服务端在接收到业务服务端推送的业务信息后,根据业务ID通过所述通道将业务信息发送至长连接的客户端;
长连接的客户端根据业务ID将业务信息推送至业务客户端。
优选地,所述长连接的服务端根据各业务的申请请求为各业务配置唯一的业务ID并发送至长连接的客户端包括:
长连接的服务端接收各业务发送的业务标示申请请求,并根据该业务标示申请请求返回业务标示至业务客户端;
长连接的客户端接收业务客户端发送的业务标示,并根据长连接的客户端所在终端的属性信息建立用以识别终端的唯一的特征值,将所述各个业务标示和特征值一起传送至所述长连接的服务端;
长连接的服务端根据所述业务标示和特征值生成与各个业务对应的业务ID,并将所述业务ID发送至长连接的客户端。
优选地,所述长连接的客户端建立用于传输数据至长连接的服务端的通道,并获取心跳时间维持长连接的存活包括:
根据当前的网络环境确定初始心跳时间;
根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈;
在未接收到所述长连接的服务端的反馈时,将所述初始心跳时间传送至所述长连接的服务端,在接收到所述长连接的服务端针对初始心跳时间的反馈时,将第二心跳时间的前一次心跳时间传送至所述长连接的服务端;
接收到所述长连接的服务端的反馈后,根据所述第二心跳时间与所述前 一次心跳时间计算初始心跳增加步长;
根据初始心跳增加步长及所述第二心跳时间计算第三心跳时间,根据初始心跳增加步长计算新的心跳增加步长,根据新的心跳增加步长和第三心跳时间计算得到第四心跳时间,直至得到的第四心跳时间达到预设的极限值或者心跳增加步长为零,将此时的第四心跳时间作为维持长连接的存活的心跳时间。
优选地,按以下公式计算心跳时间:
f(n)=2*f(n-1);
其中,n≥1,初始心跳时间f(0)为10~50秒;当n=1时,得到第一心跳时间为f(1)=2*f(0);当n递增时,得到第二心跳时间。
优选地,按以下公式计算初始心跳增加步长:
B0=(f(n)-f(n-1))/2;其中,n≥1,B0表示初始心跳增加步长,f(n)表示第二心跳时间,f(n-1)表示第二心跳时间的前一次心跳时间;
按以下公式计算新的心跳增加步长:
Bn=(Bn-1)/2;其中,n≥1,Bn表示新的心跳增加步长,Bn-1表示新的心跳增加步长的前一次心跳增加步长;
按以下公式计算第三心跳时间和第四心跳时间:
f′(n)=f′(n-1)+Bn;其中,n≥1,当n=1时,计算得到的第三心跳时间;当n递增时,得到第四心跳时间。
优选地,所述根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈包括:
当将第一心跳时间或第二心跳时间传送至所述长连接的服务端的预设传送次数未满足接收到所述长连接的服务端反馈的预置次数,则确定未接收到所述长连接的服务端的反馈。
此外,为实现上述目的,本发明还提供了一种多业务共享长连接系统,所述多业务共享长连接系统包括长连接的客户端和长连接的服务端,其中,
长连接的客户端,用于建立用于传输数据至长连接的服务端的通道,并 获取心跳时间维持长连接的存活;
长连接的服务端,用于根据各业务的申请请求为各业务配置唯一的业务ID,并将所述业务ID发送至长连接的客户端;
长连接的客户端,用于将接收到的所述业务ID传送至对应的业务客户端,以供其上报至与其对应的业务服务端;
长连接的服务端,用于在接收到业务服务端推送的业务信息后,根据业务ID通过所述通道将业务信息发送至长连接的客户端;
长连接的客户端,用于根据业务ID将业务信息推送至业务客户端。
优选地,所述长连接的服务端,还用于接收各业务发送的业务标示申请请求,并根据该业务标示申请请求返回业务标示至业务客户端;
长连接的客户端,还用于接收业务客户端发送的业务标示,并根据长连接的客户端所在终端的属性信息建立用以识别终端的唯一的特征值,将所述各个业务标示和特征值一起传送至所述长连接的服务端;
长连接的服务端,还用于根据所述业务标示和特征值生成与各个业务对应的业务ID,并将所述业务ID发送至长连接的客户端。
此外,为实现上述目的,本发明还提供了一种长连接的心跳时间获取方法,包括:
根据当前的网络环境确定初始心跳时间;
根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈;
在未接收到所述长连接的服务端的反馈时,将所述初始心跳时间传送至所述长连接的服务端,在接收到所述长连接的服务端针对初始心跳时间的反馈时,将第二心跳时间的前一次心跳时间传送至所述长连接的服务端;
接收到所述长连接的服务端的反馈后,根据所述第二心跳时间与所述前一次心跳时间计算初始心跳增加步长;
根据初始心跳增加步长及所述第二心跳时间计算第三心跳时间,根据初始心跳增加步长计算新的心跳增加步长,根据新的心跳增加步长和第三心跳 时间计算得到第四心跳时间,直至得到的第四心跳时间达到预设的极限值或者心跳增加步长为零,将此时的第四心跳时间作为维持长连接的存活的心跳时间。
优选地,按以下公式计算心跳时间:
f(n)=2*f(n-1);
其中,n≥1,初始心跳时间f(0)为10~50秒;当n=1时,得到第一心跳时间为f(1)=2*f(0);当n递增时,得到第二心跳时间。
优选地,按以下公式计算初始心跳增加步长:
B0=(f(n)-f(n-1))/2;其中,n≥1,B0表示初始心跳增加步长,f(n)表示第二心跳时间,f(n-1)表示第二心跳时间的前一次心跳时间;
按以下公式计算新的心跳增加步长:
Bn=(Bn-1)/2;其中,n≥1,Bn表示新的心跳增加步长,Bn-1表示新的心跳增加步长的前一次心跳增加步长;
按以下公式计算第三心跳时间和第四心跳时间:
f′(n)=f′(n-1)+Bn;其中,n≥1,当n=1时,计算得到的第三心跳时间;当n递增时,得到第四心跳时间。
优选地,所述所述根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈包括:
当将第一心跳时间或第二心跳时间传送至所述长连接的服务端的预设传送次数未满足接收到所述长连接的服务端反馈的预置次数,则确定未接收到所述长连接的服务端的反馈。
此外,为实现上述目的,本发明还提供了一种长连接的心跳时间获取装置,包括:
初始心跳时间获取模块,用于根据当前的网络环境确定初始心跳时间;
第二心跳时间获取模块,用于根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服 务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈;
传送模块,用于在未接收到所述长连接的服务端的反馈时,将所述初始心跳时间传送至所述长连接的服务端,在接收到所述长连接的服务端针对初始心跳时间的反馈时,将第二心跳时间的前一次心跳时间传送至所述长连接的服务端;
初始心跳增加步长获取模块,用于接收到所述长连接的服务端的反馈后,根据所述第二心跳时间与所述前一次心跳时间计算初始心跳增加步长;
第四心跳时间获取模块,用于根据初始心跳增加步长及所述第二心跳时间计算第三心跳时间,根据初始心跳增加步长计算新的心跳增加步长,根据新的心跳增加步长和第三心跳时间计算得到第四心跳时间,直至得到的第四心跳时间达到预设的极限值或者心跳增加步长为零,将此时的第四心跳时间作为维持长连接的存活的心跳时间。
优选地,按以下公式计算心跳时间:
f(n)=2*f(n-1);
其中,n≥1,初始心跳时间f(0)为10~50秒;当n=1时,得到第一心跳时间为f(1)=2*f(0);当n递增时,得到第二心跳时间。
优选地,按以下公式计算初始心跳增加步长:
B0=(f(n)-f(n-1))/2;其中,n≥1,B0表示初始心跳增加步长,f(n)表示第二心跳时间,f(n-1)表示第二心跳时间的前一次心跳时间;
按以下公式计算新的心跳增加步长:
Bn=(Bn-1)/2;其中,n≥1,Bn表示新的心跳增加步长,Bn-1表示新的心跳增加步长的前一次心跳增加步长;
按以下公式计算第三心跳时间和第四心跳时间:
f′(n)=f′(n-1)+Bn;其中,n≥1,当n=1时,计算得到的第三心跳时间;当n递增时,得到第四心跳时间。
优选地,所述第二心跳时间获取模块还用于,当将第一心跳时间或第二心跳时间传送至所述长连接的服务端的预设传送次数未满足接收到所述长连接的服务端反馈的预置次数,则确定未接收到所述长连接的服务端的反馈。
此外,为实现上述目的,本发明还提供了一种终端,所述终端包括上述结构的长连接的心跳时间获取装置。
本发明实施例中长连接的客户端通过与长连接的服务端建立通道后,获取心跳时间维持长连接的存活。该长连接供多个业务进行共享的过程中,长连接的服务端根据各业务的申请请求为各业务配置唯一的业务ID,并将业务ID发送至长连接的客户端。长连接的客户端将接收到的业务ID传送至对应的业务客户端,以供其上报至与其对应的业务服务端。长连接的服务端在接收到业务服务端推送的业务信息后,根据业务ID通过该通道将业务信息发送至长连接的客户端,长连接的客户端根据业务ID将业务信息推送至业务客户端。从而实现了多业务共享一条长连接通道,提高了长连接的利用率。
附图说明
图1为本发明多业务共享长连接方法一实施例的流程示意图;
图2为本发明多业务共享长连接方法中,长连接的服务端根据各业务的申请请求为各业务配置唯一的业务ID并发送至长连接的客户端的细化流程示意图;
图3为本发明多业务共享长连接方法中,长连接的客户端建立用于传输数据至长连接的服务端的通道,并获取心跳时间维持长连接的存活的细化流程示意图;
图4为本发明长连接的心跳时间获取方法一实施例的流程示意图;
图5为本发明长连接的心跳时间获取装置一实施例的功能模块示意图。
本发明目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
具体实施方式
应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。
如图1所示,示出了本发明一种多业务共享长连接方法一实施例。该实施例的多业务共享长连接方法包括:
步骤S10、长连接的客户端建立用于传输数据至长连接的服务端的通道,并获取心跳时间维持长连接的存活;
本实施例中,为了提高长连接中业务消息传输的安全性,可从终端的系统级层面创建一条稳定自适应的长连接。终端中的长连接的客户端需要与长连接的服务端建立用于根据网络协议传输数据的通道,该终端的类型可根据实际需要进行设置,例如,手机、电脑、智能电视等。
具体地,建立长连接的过程中,首先长连接的客户端建立一条与长连接的服务端进行传输数据的通道,例如,建立个TCPSocket。长连接的客户端根据消息协议向长连接的服务端发送上线命令,同时等待收取长连接的服务端下达命令。该消息协议可为预先设置的传输数据的网络协议,例如,长连接的客户端发送“1”为上线命令,发送“2”为下线命令,下达命令可为长连接的服务端返回“3”表示已经接收到长连接的客户端的信息。当长连接的客户端收到长连接的服务端的回复时,表明长连接的服务端已经接收到长连接的客户端发送的上线命令,此时将根据消息协议解析消息,以得到传送的消息内容,并根据内容提示进行相应的处理。然后长连接的客户端获取心跳时间,将得到的当前心跳时间传送至长连接的服务端,并等待服务端返回心跳时间。一直重复长连接的客户端在接收到长连接的服务端返回的消息后,根据消息协议解析消息及获取当前的心跳时间传送至长连接的服务端,直至得到最优心跳时间,以用得到的心跳时间维持长连接的存活,即保持通道的稳定性。建立好的该长连接供多个业务进行共享。
步骤S20、长连接的服务端根据各业务的申请请求为各业务配置唯一的业务ID,并将所述业务ID发送至长连接的客户端;
根据上述建立好的长连接,针对多个业务共享该条长连接的过程中,为了有效区分各个业务,各个业务向长连接的服务端申请获取各自的编号,即各个业务向长连接的服务端发送申请业务ID的请求,长连接的服务端收到该请求后为各业务配置唯一的业务ID,并将配置好的业务ID发送至长连接的客户端,以供长连接的客户端将业务ID传送至业务客户端。
步骤S30、长连接的客户端将接收到的所述业务ID传送至对应的业务客 户端,以供其上报至与其对应的业务服务端;
长连接的客户端接收到长连接的服务端发送过来的各业务ID后,将各业务ID传送至对应的业务客户端。各业务客户端接收到业务ID后,将业务ID上报至与其对应的业务服务端。
步骤S40、长连接的服务端在接收到业务服务端推送的业务信息后,根据业务ID通过所述通道将业务信息发送至长连接的客户端;
在上述业务服务端得到业务ID后,将要推送的业务信息与业务ID一起发送至长连接的服务端。长连接的服务端在接收到业务服务端推送的业务信息及业务ID后,根据业务ID找到长连接的客户端所在的终端,通过上述所建立的长连接的服务端与长连接的客户端之间进行数据传输的通道,将业务信息发送至长连接的客户端。
步骤S50、长连接的客户端根据业务ID将业务信息推送至业务客户端。
长连接的客户端接收到长连接的服务端发送过来的业务ID及业务信息后,根据业务ID找到相应的业务,并将业务信息推送至该业务客户端。
以下将以智能电视进行举例说明:
首先,位于智能电视的长连接的客户端创建一条与长连接的服务端之间利用网络协议传输数据的通道,即创建一条长连接,长连接的客户端可命名为com.tianci.push。
位于智能电视的升级业务、影视推送业务、模块更新业务这三条业务分别向建立好的长连接的服务端申请各自的一个业务标示。
申请得到业务标示后,升级业务、影视推送业务、模块更新业务这三个业务利用android广播,把自身包名(即业务的关键信息)和对应的业务标示发送给com.tianci.push。
com.tianci.push收到这三个业务通过广播传送过来的自身包名和对应的业务标示后,把这三个业务标示和对应的包名进行关联存储于数据库中。
com.tianci.push根据智能电视的相关信息构建一个与智能电视对应的长连接的特征值,该特征值是唯一的,该特征值可包括智能电视的版本号、物理地址等。
com.tianci.push通过长连接的数据传输通道把特征值和这三个业务标示发送给长连接的服务端,长连接的服务端根据特征值和这三个业务标示生成 每个业务对应的业务ID,并将业务ID和对应的业务标示返回给com.tianci.push。
com.tianci.push根据这三个业务的业务标示,更新数据库,即把这三个业务的业务标示、各自的业务ID、各自的包名进行关联存储于数据库中。同时找到这三个业务各自的包名,把这三个业务ID发送给对应的业务。
具体地,例如,影视推送业务收到业务ID后,将业务ID上报给影视推送业务的服务端。影视推送业务的服务端把业务ID和影视推送业务信息发送给长连接的服务端。长连接的服务端根据业务ID找到智能电视设备,将业务ID和影视推送业务信息发到位于智能电视的com.tianic.push。com.tianci.push根据业务ID,找到影视推送业务的包名,把影视推送业务信息指定送到影视推送业务的客户端。影视推送业务的客户端根据自身协议对接收到的信息进行解析及相应处理。
本发明实施例中长连接的客户端通过与长连接的服务端建立通道后,获取心跳时间维持长连接的存活。该长连接供多个业务进行共享的过程中,长连接的服务端根据各业务的申请请求为各业务配置唯一的业务ID,并将业务ID发送至长连接的客户端。长连接的客户端将接收到的业务ID传送至对应的业务客户端,以供其上报至与其对应的业务服务端。长连接的服务端在接收到业务服务端推送的业务信息后,根据业务ID通过该通道将业务信息发送至长连接的客户端,长连接的客户端根据业务ID将业务信息推送至业务客户端。从而实现了多业务共享一条长连接通道,提高了长连接的利用率。
进一步地,如图2所示,基于上述实施例,本实施例中,上述步骤S20可包括:
步骤S21、长连接的服务端接收各业务发送的业务标示申请请求,并根据该业务标示申请请求返回业务标示至业务客户端;
根据上述建立好的长连接,长连接的服务端根据各业务的申请请求为各业务配置唯一的业务ID的过程,具体地,首先每个业务向长连接的服务端申请各自的一个业务标示,长连接的服务端根据各业务发送的业务标示申请请求,返回业务标示至对应的各业务客户端。然后在终端上各个业务客户端把各自的业务标示传送至长连接的客户端。可以理解的是,该多业务为两个或 者两个以上的业务,当然如果是单一业务使用该长连接,则不需要向长连接的服务端申请业务标示。
步骤S22、长连接的客户端接收业务客户端发送的业务标示,并根据长连接的客户端所在终端的属性信息建立用以识别终端的唯一的特征值,将所述各个业务标示和特征值一起传送至所述长连接的服务端;
长连接的客户端接收到业务标示后,把各业务标示与对应业务的关键信息作为一对键值进行关联存储于数据库中,以便根据业务标示获知业务的关键信息。业务的关键信息可包括业务的名称。
本实施例中,根据长连接的客户端所在的终端,获取该终端的属性信息作为识别终端的唯一的特征值,例如,该特征值可包括连接的客户端所在终端的物理地址、版本号等。然后将各个业务标示和长连接的特征值,一起传给长连接的服务端,以供长连接的服务端根据各个业务标示和长连接的特征值生成的各个业务对应的业务ID。
步骤S23、长连接的服务端根据所述业务标示和特征值生成与各个业务对应的业务ID,并将所述业务ID发送至长连接的客户端。
长连接的服务端接收到各个业务标示和长连接的特征值后,根据每个业务向长连接的服务端申请的各自对应的业务标示,核对各个业务标示是否正确,即是否为之前向长连接的服务端申请的业务标示。若正确,则长连接的服务端根据长连接的特征值和各个业务标示,生成各个业务对应的唯一的业务ID,并将各个业务ID及对应的业务标示返回给长连接的客户端。长连接的客户端收到各个业务ID及对应的业务标示后,将每个业务对应的业务ID,通过业务标示把各个业务的业务ID、业务标示和业务关键信息三者进行关联存储于数据库中,以对上述匹配存储各个标示与对应业务的关键信息的数据库进行更新。
进一步地,如图3所示,基于上述实施例,本实施例中,上述步骤S10可包括:
步骤S11、根据当前的网络环境确定初始心跳时间;
当上述长连接的客户端与长连接的服务端建立连接后,长连接的客户端将自身相关信息发送至长连接的服务端,供长连接的服务端识别长连接的客 户端,以完成长连接的服务端上线初始化的过程。
由于初始心跳时间与网络环境有关,因此长连接的客户端通过检测当前网络环境,根据终端所处的当前网络环境初始化初始心跳时间。当然,也可以不需要检测网络环境,直接将默认的初始值赋给初始心跳时间,该默认的初始值可设置为10~50秒,或者根据具体情况而灵活设置。
步骤S12、根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈;
上述得到初始心跳时间后,长连接的客户端根据公式:f(n)=2*f(n-1)计算心跳时间,其中,n≥1,初始心跳时间f(0)为10~50秒。当n=1时,得到第一心跳时间为f(1)=2*f(0);当n递增时,得到第二心跳时间。长连接的客户端得到第一心跳时间后,将第一心跳时间传送至长连接的服务端。当接收到长连接的服务端的反馈时,说明该第一心跳时间对于维持长连接的存活是成功的,然后以第一心跳时间作为新的初始心跳时间计算第二心跳时间,即将n以1的步长递增根据公式重复计算第二心跳时间。将得到的第二心跳时间继续发送至至长连接的服务端,直至接收不到所述长连接的服务端的反馈,停止通过上述公式计算第二心跳时间。需要说明的是,长连接的服务端的反馈可以是返回长连接的客户端所发送的心跳时间,也可以是根据预先设置的协议返回指定的信息。通过上述公式重复计算第二心跳时间,使得在寻找最优心跳时间的过程中,当心跳时间快速增加时,尽量少次数找到心跳时间的临界值。
需要说明的是,为了提高获取心跳时间的可靠性,长连接的客户端可以将第一心跳时间或第二心跳时间多次传送至长连接的服务端。当将第一心跳时间或第二心跳时间传送至长连接的服务端的预设传送次数未满足接收到长连接的服务端反馈的预置次数,则确定未接收到长连接的服务端的反馈。该预设传送次数及预置次数可根据具体情况而灵活设置。例如,长连接的客户端将第一心跳时间传送3次至长连接的服务端,在这3次中,若3次都收到长连接的服务端的反馈,则说明长连接的客户端将第一心跳时间发送至长连接的服务端时,能够成功收到长连接的服务端的反馈。
步骤S13、在未接收到所述长连接的服务端的反馈时,将所述初始心跳时 间传送至所述长连接的服务端,在接收到所述长连接的服务端针对初始心跳时间的反馈时,将第二心跳时间的前一次心跳时间传送至所述长连接的服务端;
当长连接的客户端未接收到长连接的服务端针对第二心跳时间的反馈时,利用初始心跳时间进行尝试,即长连接的客户端将初始心跳时间传送至长连接的服务端,以检测长连接的客户端是否会接收到长连接的服务端返回该初始心跳时间。需要说明的是,长连接的客户端可将初始心跳时间多次传送至长连接的服务端,根据是否满足按时收到长连接的服务端的预设反馈次数而进行相应处理。例如,长连接的客户端可将初始心跳时间5次传送至长连接的服务端,当满足按时收到长连接的服务端的5次或者4次的反馈时,说明成功接收到长连接的服务端的反馈,否则失败。
本实施例中,当长连接的客户端未接收到长连接的服务端针对初始心跳时间的反馈时,转入执行步骤11,重新初始化心跳时间。当长连接的客户端接收到长连接的服务端针对初始心跳时间的反馈时,利用第二心跳时间的前一次心跳时间进行尝试,即将第二心跳时间的前一次心跳时间传送至长连接的服务端。该第二心跳时间为接收不到长连接的服务端针对第二心跳时间的反馈时,最后发送的第二心跳时间。前一次心跳时间传送的次数可根据具体情况而灵活设置,根据是否满足按时收到长连接的服务端的预设反馈次数而进行相应处理。
步骤S14、接收到所述长连接的服务端的反馈后,根据所述第二心跳时间与所述前一次心跳时间计算初始心跳增加步长;
本实施例中,当长连接的客户端未接收到长连接的服务端针对前一次心跳时间的反馈时,转入执行步骤11,重新初始化心跳时间。当长连接的客户端接收到长连接的服务端针对前一次心跳时间的反馈时,根据公式B0=(f(n)-f(n-1))/2计算初始心跳增加步长。其中,n≥1,B0表示初始心跳增加步长,f(n)表示第二心跳时间,f(n-1)表示第二心跳时间的前一次心跳时间。
步骤S15、根据初始心跳增加步长及所述第二心跳时间计算第三心跳时间,根据初始心跳增加步长计算新的心跳增加步长,根据新的心跳增加步长和第三心跳时间计算得到第四心跳时间,直至得到的第四心跳时间达到预设的极限值或者心跳增加步长为零,将此时的第四心跳时间作为维持长连接的 存活的心跳时间。
在上述得到初始心跳增加步长B0后,可根据公式:Bn=(Bn-1)/2计算新的心跳增加步长。其中,n≥1,Bn表示新的心跳增加步长,Bn-1表示新的心跳增加步长的前一次心跳增加步长。然后根据公式f′(n)=f′(n-1)+Bn计算第三心跳时间和第四心跳时间。根据该公式可在上述得到临界值后,快速寻找到最优值。其中,n≥1,当n=1时,可根据初始心跳增加步长B0及第二心跳时间计算得到的第三心跳时间。然后长连接的客户端将得到的第三心跳时间发送至长连接的服务端,并在接收到长连接的服务端的反馈时,将n以1的步长递增,根据该公式计算得到第四心跳时间。当未接收到长连接的服务端的反馈时,转入执行步骤S13,重新将初始心跳时间发送至长连接的服务端进行尝试。然后长连接的客户端将得到的第四心跳时间发送至长连接的服务端,并在接收到长连接的服务端针对第四心跳时间的反馈时,递增n继续计算第四心跳时间,直至得到的第四心跳时间达到预设的极限值或者心跳增加步长为零,将此时的第四心跳时间作为维持长连接的存活的心跳时间。
对应地,提出本发明一种多业务共享长连接系统,在本实施例中,该多业务共享长连接系统包括长连接的客户端和长连接的服务端,其中,
长连接的客户端,用于建立用于传输数据至长连接的服务端的通道,并获取心跳时间维持长连接的存活;
本实施例中,为了提高长连接中业务消息传输的安全性,可从终端的系统级层面创建一条稳定自适应的长连接。终端中的长连接的客户端需要与长连接的服务端建立用于根据网络协议传输数据的通道,该终端的类型可根据实际需要进行设置,例如,手机、电脑、智能电视等。
具体地,建立长连接的过程中,首先长连接的客户端建立一条与长连接的服务端进行传输数据的通道,例如,建立个TCPSocket。长连接的客户端根据消息协议向长连接的服务端发送上线命令,同时等待收取长连接的服务端下达命令。该消息协议可为预先设置的传输数据的网络协议,例如,长连接的客户端发送“1”为上线命令,发送“2”为下线命令,下达命令可为长连接的服务端返回“3”表示已经接收到长连接的客户端的信息。当长连接的客户端收到长连接的服务端的回复时,表明长连接的服务端已经接收到长连接 的客户端发送的上线命令,此时将根据消息协议解析消息,以得到传送的消息内容,并根据内容提示进行相应的处理。然后长连接的客户端获取心跳时间,将得到的当前心跳时间传送至长连接的服务端,并等待服务端返回心跳时间。一直重复长连接的客户端在接收到长连接的服务端返回的消息后,根据消息协议解析消息及获取当前的心跳时间传送至长连接的服务端,直至得到最优心跳时间,以用得到的心跳时间维持长连接的存活,即保持通道的稳定性。建立好的该长连接供多个业务进行共享。
长连接的服务端,用于根据各业务的申请请求为各业务配置唯一的业务ID,并将所述业务ID发送至长连接的客户端;
根据上述建立好的长连接,针对多个业务共享该条长连接的过程中,为了有效区分各个业务,各个业务向长连接的服务端申请获取各自的编号,即各个业务向长连接的服务端发送申请业务ID的请求,长连接的服务端收到该请求后为各业务配置唯一的业务ID,并将配置好的业务ID发送至长连接的客户端,以供长连接的客户端将业务ID传送至业务客户端。
长连接的客户端,用于将接收到的所述业务ID传送至对应的业务客户端,以供其上报至与其对应的业务服务端;
长连接的客户端接收到长连接的服务端发送过来的各业务ID后,将各业务ID传送至对应的业务客户端。各业务客户端接收到业务ID后,将业务ID上报至与其对应的业务服务端。
长连接的服务端,用于在接收到业务服务端推送的业务信息后,根据业务ID通过所述通道将业务信息发送至长连接的客户端;
在上述业务服务端得到业务ID后,将要推送的业务信息与业务ID一起发送至长连接的服务端。长连接的服务端在接收到业务服务端推送的业务信息及业务ID后,根据业务ID找到长连接的客户端所在的终端,通过上述所建立的长连接的服务端与长连接的客户端之间进行数据传输的通道,将业务信息发送至长连接的客户端。
长连接的客户端,用于根据业务ID将业务信息推送至业务客户端。
长连接的客户端接收到长连接的服务端发送过来的业务ID及业务信息后,根据业务ID找到相应的业务,并将业务信息推送至该业务客户端。
以下将以智能电视进行举例说明:
首先,位于智能电视的长连接的客户端创建一条与长连接的服务端之间利用网络协议传输数据的通道,即创建一条长连接,长连接的客户端可命名为com.tianci.push。
位于智能电视的升级业务、影视推送业务、模块更新业务这三条业务分别向建立好的长连接的服务端申请各自的一个业务标示。
申请得到业务标示后,升级业务、影视推送业务、模块更新业务这三个业务利用android广播,把自身包名(即业务的关键信息)和对应的业务标示发送给com.tianci.push。
com.tianci.push收到这三个业务通过广播传送过来的自身包名和对应的业务标示后,把这三个业务标示和对应的包名进行关联存储于数据库中。
com.tianci.push根据智能电视的相关信息构建一个与智能电视对应的长连接的特征值,该特征值是唯一的,该特征值可包括智能电视的版本号、物理地址等。
com.tianci.push通过长连接的数据传输通道把特征值和这三个业务标示发送给长连接的服务端,长连接的服务端根据特征值和这三个业务标示生成每个业务对应的业务ID,并将业务ID和对应的业务标示返回给com.tianci.push。
com.tianci.push根据这三个业务的业务标示,更新数据库,即把这三个业务的业务标示、各自的业务ID、各自的包名进行关联存储于数据库中。同时找到这三个业务各自的包名,把这三个业务ID发送给对应的业务。
具体地,例如,影视推送业务收到业务ID后,将业务ID上报给影视推送业务的服务端。影视推送业务的服务端把业务ID和影视推送业务信息发送给长连接的服务端。长连接的服务端根据业务ID找到智能电视设备,将业务ID和影视推送业务信息发到位于智能电视的com.tianic.push。com.tianci.push根据业务ID,找到影视推送业务的包名,把影视推送业务信息指定送到影视推送业务的客户端。影视推送业务的客户端根据自身协议对接收到的信息进行解析及相应处理。
本发明实施例中长连接的客户端通过与长连接的服务端建立通道后,获取心跳时间维持长连接的存活。该长连接供多个业务进行共享的过程中,长连接的服务端根据各业务的申请请求为各业务配置唯一的业务ID,并将业务 ID发送至长连接的客户端。长连接的客户端将接收到的业务ID传送至对应的业务客户端,以供其上报至与其对应的业务服务端。长连接的服务端在接收到业务服务端推送的业务信息后,根据业务ID通过该通道将业务信息发送至长连接的客户端,长连接的客户端根据业务ID将业务信息推送至业务客户端。从而实现了多业务共享一条长连接通道,提高了长连接的利用率。
进一步地,在本实施例中,所述长连接的服务端,还用于接收各业务发送的业务标示申请请求,并根据该业务标示申请请求返回业务标示至业务客户端;
根据上述建立好的长连接,长连接的服务端根据各业务的申请请求为各业务配置唯一的业务ID的过程,具体地,首先每个业务向长连接的服务端申请各自的一个业务标示,长连接的服务端根据各业务发送的业务标示申请请求,返回业务标示至对应的各业务客户端。然后在终端上各个业务客户端把各自的业务标示传送至长连接的客户端。可以理解的是,该多业务为两个或者两个以上的业务,当然如果是单一业务使用该长连接,则不需要向长连接的服务端申请业务标示。
长连接的客户端,还用于接收业务客户端发送的业务标示,并根据长连接的客户端所在终端的属性信息建立用以识别终端的唯一的特征值,将所述各个业务标示和特征值一起传送至所述长连接的服务端;
长连接的客户端接收到业务标示后,把各业务标示与对应业务的关键信息作为一对键值进行关联存储于数据库中,以便根据业务标示获知业务的关键信息。业务的关键信息可包括业务的名称。
本实施例中,根据长连接的客户端所在的终端,获取该终端的属性信息作为识别终端的唯一的特征值,例如,该特征值可包括连接的客户端所在终端的物理地址、版本号等。然后将各个业务标示和长连接的特征值,一起传给长连接的服务端,以供长连接的服务端根据各个业务标示和长连接的特征值生成的各个业务对应的业务ID。
长连接的服务端,还用于根据所述业务标示和特征值生成与各个业务对应的业务ID,并将所述业务ID发送至长连接的客户端。
长连接的服务端接收到各个业务标示和长连接的特征值后,根据每个业 务向长连接的服务端申请的各自对应的业务标示,核对各个业务标示是否正确,即是否为之前向长连接的服务端申请的业务标示。若正确,则长连接的服务端根据长连接的特征值和各个业务标示,生成各个业务对应的唯一的业务ID,并将各个业务ID及对应的业务标示返回给长连接的客户端。长连接的客户端收到各个业务ID及对应的业务标示后,将每个业务对应的业务ID,通过业务标示把各个业务的业务ID、业务标示和业务关键信息三者进行关联存储于数据库中,以对上述匹配存储各个标示与对应业务的关键信息的数据库进行更新。
对应地,如图4所示,提出本发明一种长连接的心跳时间获取方法一实施例。该实施例的长连接的心跳时间获取方法包括:
步骤S1、根据当前的网络环境确定初始心跳时间;
当上述长连接的客户端与长连接的服务端建立连接后,长连接的客户端将自身相关信息发送至长连接的服务端,供长连接的服务端识别长连接的客户端,以完成长连接的服务端上线初始化的过程。
由于初始心跳时间与网络环境有关,因此长连接的客户端通过检测当前网络环境,根据终端所处的当前网络环境初始化初始心跳时间。当然,也可以不需要检测网络环境,直接将默认的初始值赋给初始心跳时间,该默认的初始值可设置为10~50秒,或者根据具体情况而灵活设置。
步骤S2、根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈;
上述得到初始心跳时间后,长连接的客户端根据公式:f(n)=2*f(n-1)计算心跳时间,其中,n≥1,初始心跳时间f(0)为10~50秒。当n=1时,得到第一心跳时间为f(1)=2*f(0);当n递增时,得到第二心跳时间。长连接的客户端得到第一心跳时间后,将第一心跳时间传送至长连接的服务端。当接收到长连接的服务端的反馈时,说明该第一心跳时间对于维持长连接的存活是成功的,然后以第一心跳时间作为新的初始心跳时间计算第二心跳时间,即将n以1的步长递增根据公式重复计算第二心跳时间。将得到的第二心跳时间继续发 送至至长连接的服务端,直至接收不到所述长连接的服务端的反馈,停止通过上述公式计算第二心跳时间。需要说明的是,长连接的服务端的反馈可以是返回长连接的客户端所发送的心跳时间,也可以是根据预先设置的协议返回指定的信息。通过上述公式重复计算第二心跳时间,使得在寻找最优心跳时间的过程中,当心跳时间快速增加时,尽量少次数找到心跳时间的临界值。
需要说明的是,为了提高获取心跳时间的可靠性,长连接的客户端可以将第一心跳时间或第二心跳时间多次传送至长连接的服务端。当将第一心跳时间或第二心跳时间传送至长连接的服务端的预设传送次数未满足接收到长连接的服务端反馈的预置次数,则确定未接收到长连接的服务端的反馈。该预设传送次数及预置次数可根据具体情况而灵活设置。例如,长连接的客户端将第一心跳时间传送3次至长连接的服务端,在这3次中,若3次都收到长连接的服务端的反馈,则说明长连接的客户端将第一心跳时间发送至长连接的服务端时,能够成功收到长连接的服务端的反馈。
步骤S3、在未接收到所述长连接的服务端的反馈时,将所述初始心跳时间传送至所述长连接的服务端,在接收到所述长连接的服务端针对初始心跳时间的反馈时,将第二心跳时间的前一次心跳时间传送至所述长连接的服务端;
当长连接的客户端未接收到长连接的服务端针对第二心跳时间的反馈时,利用初始心跳时间进行尝试,即长连接的客户端将初始心跳时间传送至长连接的服务端,以检测长连接的客户端是否会接收到长连接的服务端返回该初始心跳时间。需要说明的是,长连接的客户端可将初始心跳时间多次传送至长连接的服务端,根据是否满足按时收到长连接的服务端的预设反馈次数而进行相应处理。例如,长连接的客户端可将初始心跳时间5次传送至长连接的服务端,当满足按时收到长连接的服务端的5次或者4次的反馈时,说明成功接收到长连接的服务端的反馈,否则失败。
本实施例中,当长连接的客户端未接收到长连接的服务端针对初始心跳时间的反馈时,转入执行步骤1,重新初始化心跳时间。当长连接的客户端接收到长连接的服务端针对初始心跳时间的反馈时,利用第二心跳时间的前一次心跳时间进行尝试,即将第二心跳时间的前一次心跳时间传送至长连接的服务端。该第二心跳时间为接收不到长连接的服务端针对第二心跳时间的反 馈时,最后发送的第二心跳时间。前一次心跳时间传送的次数可根据具体情况而灵活设置,根据是否满足按时收到长连接的服务端的预设反馈次数而进行相应处理。
步骤S4、接收到所述长连接的服务端的反馈后,根据所述第二心跳时间与所述前一次心跳时间计算初始心跳增加步长;
本实施例中,当长连接的客户端未接收到长连接的服务端针对前一次心跳时间的反馈时,转入执行步骤1,重新初始化心跳时间。当长连接的客户端接收到长连接的服务端针对前一次心跳时间的反馈时,根据公式B0=(f(n)-f(n-1))/2计算初始心跳增加步长。其中,n≥1,B0表示初始心跳增加步长,f(n)表示第二心跳时间,f(n-1)表示第二心跳时间的前一次心跳时间。
步骤S5、根据初始心跳增加步长及所述第二心跳时间计算第三心跳时间,根据初始心跳增加步长计算新的心跳增加步长,根据新的心跳增加步长和第三心跳时间计算得到第四心跳时间,直至得到的第四心跳时间达到预设的极限值或者心跳增加步长为零,将此时的第四心跳时间作为维持长连接的存活的心跳时间。
在上述得到初始心跳增加步长B0后,可根据公式:Bn=(Bn-1)/2计算新的心跳增加步长。其中,n≥1,Bn表示新的心跳增加步长,Bn-1表示新的心跳增加步长的前一次心跳增加步长。然后根据公式f′(n)=f′(n-1)+Bn计算第三心跳时间和第四心跳时间。根据该公式可在上述得到临界值后,快速寻找到最优值。其中,n≥1,当n=1时,可根据初始心跳增加步长B0及第二心跳时间计算得到的第三心跳时间。然后长连接的客户端将得到的第三心跳时间发送至长连接的服务端,并在接收到长连接的服务端的反馈时,将n以1的步长递增,根据该公式计算得到第四心跳时间。当未接收到长连接的服务端的反馈时,转入执行步骤S3,重新将初始心跳时间发送至长连接的服务端进行尝试。然后长连接的客户端将得到的第四心跳时间发送至长连接的服务端,并在接收到长连接的服务端针对第四心跳时间的反馈时,递增n继续计算第四心跳时间,直至得到的第四心跳时间达到预设的极限值或者心跳增加步长为零,将此时的第四心跳时间作为维持长连接的存活的心跳时间。
对应地,如图5所示,提出本发明一种长连接的心跳时间获取装置一实 施例。该实施例的长连接的心跳时间获取装置包括:
初始心跳时间获取模块100,用于根据当前的网络环境确定初始心跳时间;
当上述长连接的客户端与长连接的服务端建立连接后,长连接的客户端将自身相关信息发送至长连接的服务端,供长连接的服务端识别长连接的客户端,以完成长连接的服务端上线初始化的过程。
由于初始心跳时间与网络环境有关,因此长连接的客户端通过检测当前网络环境,由初始心跳时间获取模块100根据终端所处的当前网络环境初始化初始心跳时间。当然,也可以不需要检测网络环境,直接将默认的初始值赋给初始心跳时间,该默认的初始值可设置为10~50秒,或者根据具体情况而灵活设置。
第二心跳时间获取模块200,用于根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈;
上述得到初始心跳时间后,长连接的客户端调用第二心跳时间获取模块200根据公式:f(n)=2*f(n-1)计算心跳时间,其中,n≥1,初始心跳时间f(0)为10~50秒。当n=1时,得到第一心跳时间为f(1)=2*f(0);当n递增时,得到第二心跳时间。长连接的客户端得到第一心跳时间后,将第一心跳时间传送至长连接的服务端。当接收到长连接的服务端的反馈时,说明该第一心跳时间对于维持长连接的存活是成功的,然后以第一心跳时间作为新的初始心跳时间计算第二心跳时间,即将n以1的步长递增根据公式重复计算第二心跳时间。将得到的第二心跳时间继续发送至至长连接的服务端,直至接收不到所述长连接的服务端的反馈,停止通过上述公式计算第二心跳时间。需要说明的是,长连接的服务端的反馈可以是返回长连接的客户端所发送的心跳时间,也可以是根据预先设置的协议返回指定的信息。通过上述公式重复计算第二心跳时间,使得在寻找最优心跳时间的过程中,当心跳时间快速增加时,尽量少次数找到心跳时间的临界值。
需要说明的是,为了提高获取心跳时间的可靠性,长连接的客户端可以 将第一心跳时间或第二心跳时间多次传送至长连接的服务端。当将第一心跳时间或第二心跳时间传送至长连接的服务端的预设传送次数未满足接收到长连接的服务端反馈的预置次数,则确定未接收到长连接的服务端的反馈。该预设传送次数及预置次数可根据具体情况而灵活设置。例如,长连接的客户端将第一心跳时间传送3次至长连接的服务端,在这3次中,若3次都收到长连接的服务端的反馈,则说明长连接的客户端将第一心跳时间发送至长连接的服务端时,能够成功收到长连接的服务端的反馈。
传送模块300,用于在未接收到所述长连接的服务端的反馈时,将所述初始心跳时间传送至所述长连接的服务端,在接收到所述长连接的服务端针对初始心跳时间的反馈时,将第二心跳时间的前一次心跳时间传送至所述长连接的服务端;
当长连接的客户端未接收到长连接的服务端针对第二心跳时间的反馈时,利用初始心跳时间进行尝试,即长连接的客户端调用传送模块300将初始心跳时间传送至长连接的服务端,以检测长连接的客户端是否会接收到长连接的服务端返回该初始心跳时间。需要说明的是,长连接的客户端可将初始心跳时间多次传送至长连接的服务端,根据是否满足按时收到长连接的服务端的预设反馈次数而进行相应处理。例如,长连接的客户端可将初始心跳时间5次传送至长连接的服务端,当满足按时收到长连接的服务端的5次或者4次的反馈时,说明成功接收到长连接的服务端的反馈,否则失败。
本实施例中,当长连接的客户端未接收到长连接的服务端针对初始心跳时间的反馈时,重新初始化心跳时间。当长连接的客户端接收到长连接的服务端针对初始心跳时间的反馈时,利用第二心跳时间的前一次心跳时间进行尝试,即由传送模块300将第二心跳时间的前一次心跳时间传送至长连接的服务端。该第二心跳时间为接收不到长连接的服务端针对第二心跳时间的反馈时,最后发送的第二心跳时间。前一次心跳时间传送的次数可根据具体情况而灵活设置,根据是否满足按时收到长连接的服务端的预设反馈次数而进行相应处理。
初始心跳增加步长获取模块400,用于接收到所述长连接的服务端的反馈后,根据所述第二心跳时间与所述前一次心跳时间计算初始心跳增加步长;
本实施例中,当长连接的客户端未接收到长连接的服务端针对前一次心 跳时间的反馈时,重新初始化心跳时间。当长连接的客户端接收到长连接的服务端针对前一次心跳时间的反馈时,由初始心跳增加步长获取模块400根据公式B0=(f(n)-f(n-1))/2计算初始心跳增加步长。其中,n≥1,B0表示初始心跳增加步长,f(n)表示第二心跳时间,f(n-1)表示第二心跳时间的前一次心跳时间。
第四心跳时间获取模块500,用于根据初始心跳增加步长及所述第二心跳时间计算第三心跳时间,根据初始心跳增加步长计算新的心跳增加步长,根据新的心跳增加步长和第三心跳时间计算得到第四心跳时间,直至得到的第四心跳时间达到预设的极限值或者心跳增加步长为零,将此时的第四心跳时间作为维持长连接的存活的心跳时间。
在上述得到初始心跳增加步长B0后,第四心跳时间获取模块500可根据公式:Bn=(Bn-1)/2计算新的心跳增加步长。其中,n≥1,Bn表示新的心跳增加步长,Bn-1表示新的心跳增加步长的前一次心跳增加步长。然后由第四心跳时间获取模块500根据公式f′(n)=f′(n-1)+Bn计算第三心跳时间和第四心跳时间。根据该公式可在上述得到临界值后,快速寻找到最优值。其中,n≥1,当n=1时,可根据初始心跳增加步长B0及第二心跳时间计算得到的第三心跳时间。然后长连接的客户端将得到的第三心跳时间发送至长连接的服务端,并在接收到长连接的服务端的反馈时,将n以1的步长递增,根据该公式计算得到第四心跳时间。当未接收到长连接的服务端的反馈时,重新将初始心跳时间发送至长连接的服务端进行尝试。然后长连接的客户端将得到的第四心跳时间发送至长连接的服务端,并在接收到长连接的服务端针对第四心跳时间的反馈时,递增n继续计算第四心跳时间,直至得到的第四心跳时间达到预设的极限值或者心跳增加步长为零,将此时的第四心跳时间作为维持长连接的存活的心跳时间。
对应地,本发明一种提出终端,该终端包括上述结构的长连接的心跳时间获取装置,即包括初始心跳时间获取模块100、第二心跳时间获取模块200、传送模块300、初始心跳增加步长获取模块400及第四心跳时间获取模块500,该终端。该终端可以是手机、电脑、智能电视等。
以上仅为本发明的优选实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。

Claims (20)

  1. 一种多业务共享长连接方法,其特征在于,所述多业务共享长连接方法包括以下步骤:
    长连接的客户端建立用于传输数据至长连接的服务端的通道,并获取心跳时间维持长连接的存活;
    长连接的服务端根据各业务的申请请求为各业务配置唯一的业务ID,并将所述业务ID发送至长连接的客户端;
    长连接的客户端将接收到的所述业务ID传送至对应的业务客户端,以供其上报至与其对应的业务服务端;
    长连接的服务端在接收到业务服务端推送的业务信息后,根据业务ID通过所述通道将业务信息发送至长连接的客户端;
    长连接的客户端根据业务ID将业务信息推送至业务客户端。
  2. 如权利要求1所述的多业务共享长连接方法,其特征在于,所述长连接的服务端根据各业务的申请请求为各业务配置唯一的业务ID并发送至长连接的客户端包括:
    长连接的服务端接收各业务发送的业务标示申请请求,并根据该业务标示申请请求返回业务标示至业务客户端;
    长连接的客户端接收业务客户端发送的业务标示,并根据长连接的客户端所在终端的属性信息建立用以识别终端的唯一的特征值,将所述各个业务标示和特征值一起传送至所述长连接的服务端;
    长连接的服务端根据所述业务标示和特征值生成与各个业务对应的业务ID,并将所述业务ID发送至长连接的客户端。
  3. 如权利要求1所述的多业务共享长连接方法,其特征在于,所述长连接的客户端建立用于传输数据至长连接的服务端的通道,并获取心跳时间维持长连接的存活包括:
    根据当前的网络环境确定初始心跳时间;
    根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时 间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈;
    在未接收到所述长连接的服务端的反馈时,将所述初始心跳时间传送至所述长连接的服务端,在接收到所述长连接的服务端针对初始心跳时间的反馈时,将第二心跳时间的前一次心跳时间传送至所述长连接的服务端;
    接收到所述长连接的服务端的反馈后,根据所述第二心跳时间与所述前一次心跳时间计算初始心跳增加步长;
    根据初始心跳增加步长及所述第二心跳时间计算第三心跳时间,根据初始心跳增加步长计算新的心跳增加步长,根据新的心跳增加步长和第三心跳时间计算得到第四心跳时间,直至得到的第四心跳时间达到预设的极限值或者心跳增加步长为零,将此时的第四心跳时间作为维持长连接的存活的心跳时间。
  4. 如权利要求3所述的多业务共享长连接方法,其特征在于,按以下公式计算心跳时间:
    f(n)=2*f(n-1);
    其中,n≥1,初始心跳时间f(0)为10~50秒;当n=1时,得到第一心跳时间为f(1)=2*f(0);当n递增时,得到第二心跳时间。
  5. 如权利要求4所述的多业务共享长连接方法,其特征在于,按以下公式计算初始心跳增加步长:
    B0=(f(n)-f(n-1))/2;其中,n≥1,B0表示初始心跳增加步长,f(n)表示第二心跳时间,f(n-1)表示第二心跳时间的前一次心跳时间;
    按以下公式计算新的心跳增加步长:
    Bn=(Bn-1)/2;其中,n≥1,Bn表示新的心跳增加步长,Bn-1表示新的心跳增加步长的前一次心跳增加步长;
    按以下公式计算第三心跳时间和第四心跳时间:
    f′(n)=f′(n-1)+Bn;其中,n≥1,当n=1时,计算得到的第三心跳时间;当n递增时,得到第四心跳时间。
  6. 如权利要求3所述的多业务共享长连接方法,其特征在于,所述根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈包括:
    当将第一心跳时间或第二心跳时间传送至所述长连接的服务端的预设传送次数未满足接收到所述长连接的服务端反馈的预置次数,则确定未接收到所述长连接的服务端的反馈。
  7. 如权利要求5所述的多业务共享长连接方法,其特征在于,所述根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈包括:
    当将第一心跳时间或第二心跳时间传送至所述长连接的服务端的预设传送次数未满足接收到所述长连接的服务端反馈的预置次数,则确定未接收到所述长连接的服务端的反馈。
  8. 一种多业务共享长连接系统,其特征在于,所述多业务共享长连接系统包括长连接的客户端和长连接的服务端,其中,
    长连接的客户端,用于建立用于传输数据至长连接的服务端的通道,并获取心跳时间维持长连接的存活;
    长连接的服务端,用于根据各业务的申请请求为各业务配置唯一的业务ID,并将所述业务ID发送至长连接的客户端;
    长连接的客户端,用于将接收到的所述业务ID传送至对应的业 务客户端,以供其上报至与其对应的业务服务端;
    长连接的服务端,用于在接收到业务服务端推送的业务信息后,根据业务ID通过所述通道将业务信息发送至长连接的客户端;
    长连接的客户端,用于根据业务ID将业务信息推送至业务客户端。
  9. 如权利要求8所述的多业务共享长连接系统,其特征在于,所述长连接的服务端,还用于接收各业务发送的业务标示申请请求,并根据该业务标示申请请求返回业务标示至业务客户端;
    长连接的客户端,还用于接收业务客户端发送的业务标示,并根据长连接的客户端所在终端的属性信息建立用以识别终端的唯一的特征值,将所述各个业务标示和特征值一起传送至所述长连接的服务端;
    长连接的服务端,还用于根据所述业务标示和特征值生成与各个业务对应的业务ID,并将所述业务ID发送至长连接的客户端。
  10. 一种长连接的心跳时间获取方法,其特征在于,所述长连接的心跳时间获取方法包括以下步骤:
    根据当前的网络环境确定初始心跳时间;
    根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈;
    在未接收到所述长连接的服务端的反馈时,将所述初始心跳时间传送至所述长连接的服务端,在接收到所述长连接的服务端针对初始心跳时间的反馈时,将第二心跳时间的前一次心跳时间传送至所述长连接的服务端;
    接收到所述长连接的服务端的反馈后,根据所述第二心跳时间与所述前一次心跳时间计算初始心跳增加步长;
    根据初始心跳增加步长及所述第二心跳时间计算第三心跳时间,根据初始心跳增加步长计算新的心跳增加步长,根据新的心跳增加步长和第三心跳时间计算得到第四心跳时间,直至得到的第四心跳时间达到预设的极限值或者心跳增加步长为零,将此时的第四心跳时间作为维持长连接的存活的心跳时间。
  11. 如权利要求10所述的长连接的心跳时间获取方法,其特征在于,按以下公式计算心跳时间:
    f(n)=2*f(n-1);
    其中,n≥1,初始心跳时间f(0)为10~50秒;当n=1时,得到第一心跳时间为f(1)=2*f(0);当n递增时,得到第二心跳时间。
  12. 如权利要求11所述的长连接的心跳时间获取方法,其特征在于,按以下公式计算初始心跳增加步长:
    B0=(f(n)-f(n-1))/2;其中,n≥1,B0表示初始心跳增加步长,f(n)表示第二心跳时间,f(n-1)表示第二心跳时间的前一次心跳时间;
    按以下公式计算新的心跳增加步长:
    Bn=(Bn-1)/2;其中,n≥1,Bn表示新的心跳增加步长,Bn-1表示新的心跳增加步长的前一次心跳增加步长;
    按以下公式计算第三心跳时间和第四心跳时间:
    f′(n)=f′(n-1)+Bn;其中,n≥1,当n=1时,计算得到的第三心跳时间;当n递增时,得到第四心跳时间。
  13. 如权利要求10所述的长连接的心跳时间获取方法,其特征在于,所述所述根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈包括:
    当将第一心跳时间或第二心跳时间传送至所述长连接的服务端 的预设传送次数未满足接收到所述长连接的服务端反馈的预置次数,则确定未接收到所述长连接的服务端的反馈。
  14. 如权利要求12所述的长连接的心跳时间获取方法,其特征在于,所述所述根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈包括:
    当将第一心跳时间或第二心跳时间传送至所述长连接的服务端的预设传送次数未满足接收到所述长连接的服务端反馈的预置次数,则确定未接收到所述长连接的服务端的反馈。
  15. 一种长连接的心跳时间获取装置,其特征在于,所述长连接的心跳时间获取装置包括:
    初始心跳时间获取模块,用于根据当前的网络环境确定初始心跳时间;
    第二心跳时间获取模块,用于根据所述初始心跳时间计算第一心跳时间,并将所述第一心跳时间传送至所述长连接的服务端,接收到所述长连接的服务端的反馈时,以第一心跳时间作为新的初始心跳时间计算第二心跳时间,继续发送第二心跳时间至长连接的服务端,直至接收不到所述长连接的服务端的反馈;
    传送模块,用于在未接收到所述长连接的服务端的反馈时,将所述初始心跳时间传送至所述长连接的服务端,在接收到所述长连接的服务端针对初始心跳时间的反馈时,将第二心跳时间的前一次心跳时间传送至所述长连接的服务端;
    初始心跳增加步长获取模块,用于接收到所述长连接的服务端的反馈后,根据所述第二心跳时间与所述前一次心跳时间计算初始心跳增加步长;
    第四心跳时间获取模块,用于根据初始心跳增加步长及所述第二 心跳时间计算第三心跳时间,根据初始心跳增加步长计算新的心跳增加步长,根据新的心跳增加步长和第三心跳时间计算得到第四心跳时间,直至得到的第四心跳时间达到预设的极限值或者心跳增加步长为零,将此时的第四心跳时间作为维持长连接的存活的心跳时间。
  16. 如权利要求15所述的长连接的心跳时间获取装置,其特征在于,按以下公式计算心跳时间:
    f(n)=2*f(n-1);
    其中,n≥1,初始心跳时间f(0)为10~50秒;当n=1时,得到第一心跳时间为f(1)=2*f(0);当n递增时,得到第二心跳时间。
  17. 如权利要求16所述的长连接的心跳时间获取装置,其特征在于,按以下公式计算初始心跳增加步长:
    B0=(f(n)-f(n-1))/2;其中,n≥1,B0表示初始心跳增加步长,f(n)表示第二心跳时间,f(n-1)表示第二心跳时间的前一次心跳时间;
    按以下公式计算新的心跳增加步长:
    Bn=(Bn-1)/2;其中,n≥1,Bn表示新的心跳增加步长,Bn-1表示新的心跳增加步长的前一次心跳增加步长;
    按以下公式计算第三心跳时间和第四心跳时间:
    f′(n)=f′(n-1)+Bn;其中,n≥1,当n=1时,计算得到的第三心跳时间;当n递增时,得到第四心跳时间。
  18. 如权利要求15所述的长连接的心跳时间获取装置,其特征在于,所述第二心跳时间获取模块还用于,当将第一心跳时间或第二心跳时间传送至所述长连接的服务端的预设传送次数未满足接收到所述长连接的服务端反馈的预置次数,则确定未接收到所述长连接的服务端的反馈。
  19. 如权利要求17所述的长连接的心跳时间获取装置,其特征在于,所述第二心跳时间获取模块还用于,当将第一心跳时间或第二 心跳时间传送至所述长连接的服务端的预设传送次数未满足接收到所述长连接的服务端反馈的预置次数,则确定未接收到所述长连接的服务端的反馈。
  20. 一种终端,其特征在于,所述终端包括如权利要求15所述的长连接的心跳时间获取装置。
PCT/CN2015/097955 2015-09-08 2015-12-18 多业务共享长连接方法、系统及其装置、终端 WO2017041381A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
AU2015400309A AU2015400309B2 (en) 2015-09-08 2015-12-18 Long connection sharing method for multi-businesses, system and device, terminal
US15/414,627 US10263872B2 (en) 2015-09-08 2017-01-25 Long connection sharing method for multi-businesses, system and device, terminal

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510567873.5 2015-09-08
CN201510567873.5A CN105227398B (zh) 2015-09-08 2015-09-08 多业务共享长连接方法、系统及其装置、终端

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US15/414,627 Continuation US10263872B2 (en) 2015-09-08 2017-01-25 Long connection sharing method for multi-businesses, system and device, terminal

Publications (1)

Publication Number Publication Date
WO2017041381A1 true WO2017041381A1 (zh) 2017-03-16

Family

ID=54996108

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/097955 WO2017041381A1 (zh) 2015-09-08 2015-12-18 多业务共享长连接方法、系统及其装置、终端

Country Status (4)

Country Link
US (1) US10263872B2 (zh)
CN (1) CN105227398B (zh)
AU (1) AU2015400309B2 (zh)
WO (1) WO2017041381A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111092809A (zh) * 2019-12-30 2020-05-01 北京每日优鲜电子商务有限公司 实时推送信息的方法、装置、计算机设备及存储介质

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106911795A (zh) * 2017-03-27 2017-06-30 努比亚技术有限公司 一种数据请求处理装置及方法
CN109547511B (zh) * 2017-09-22 2022-02-22 中国移动通信集团浙江有限公司 一种web消息实时推送方法、服务器、客户端及系统
CN108763200A (zh) * 2018-05-15 2018-11-06 达而观信息科技(上海)有限公司 中文分词方法及装置
CN109286665B (zh) * 2018-09-17 2021-04-20 北京龙拳风暴科技有限公司 实时移动游戏长链接处理方法及装置
CN114205270B (zh) * 2020-09-17 2023-09-22 北京三快在线科技有限公司 设备状态确定方法、装置、存储介质及电子设备
CN112187899B (zh) * 2020-09-18 2022-05-06 北京金山云网络技术有限公司 云托管通信方法、装置、系统、计算机设备和存储介质
CN112383617A (zh) * 2020-11-12 2021-02-19 百度在线网络技术(北京)有限公司 进行长连接的方法、装置、终端设备以及介质
CN115396313A (zh) * 2022-08-22 2022-11-25 度小满科技(北京)有限公司 通信方法、装置、存储介质及电子装置
CN116600016A (zh) * 2023-07-19 2023-08-15 苏州浪潮智能科技有限公司 站点调用方法及装置、存储介质及电子装置

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080165796A1 (en) * 2007-01-05 2008-07-10 International Business Machines Corporation Method for a heartbeat algorithm for a dynamically changing network environment
CN103139303A (zh) * 2013-02-07 2013-06-05 网易(杭州)网络有限公司 一种用于保持连接的心跳方法、装置及系统
CN103916442A (zh) * 2013-01-07 2014-07-09 阿里巴巴集团控股有限公司 消息推送实现方法、移动终端及消息推送系统
CN103986740A (zh) * 2013-02-07 2014-08-13 中兴通讯股份有限公司 一种支持多终端应用的永远在线架构的方法及设备及系统
CN104144159A (zh) * 2014-06-26 2014-11-12 腾讯科技(深圳)有限公司 智能心跳保活方法及智能心跳保活系统
CN104767775A (zh) * 2014-01-06 2015-07-08 腾讯科技(深圳)有限公司 网页应用消息推送方法及系统

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4509536B2 (ja) * 2003-11-12 2010-07-21 株式会社日立製作所 情報管理を支援する情報処理装置、情報管理方法、プログラム、および記録媒体
US20090251283A1 (en) * 2006-05-02 2009-10-08 Orient Instrument Computer Co., Ltd. Property management system
WO2009061399A1 (en) * 2007-11-05 2009-05-14 Nagaraju Bandaru Method for crawling, mapping and extracting information associated with a business using heuristic and semantic analysis
CN102291808B (zh) * 2011-06-03 2013-12-04 莫雅静 一种网络通信方法、通信设备以及通信设备的中间件
CN103684815B (zh) * 2012-09-03 2017-02-01 中国移动通信集团公司 数据传输链路的保活方法、装置及系统
US10475075B2 (en) * 2013-03-15 2019-11-12 Marchex, Inc. Correlated consumer telephone numbers and user identifiers for advertising retargeting
CN103685241A (zh) * 2013-11-26 2014-03-26 中国科学院计算技术研究所 一种维持tcp长连接的自适应心跳方法及其系统
US20150301875A1 (en) * 2014-04-22 2015-10-22 Andreas Harnesk Persisting and managing application messages

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080165796A1 (en) * 2007-01-05 2008-07-10 International Business Machines Corporation Method for a heartbeat algorithm for a dynamically changing network environment
CN103916442A (zh) * 2013-01-07 2014-07-09 阿里巴巴集团控股有限公司 消息推送实现方法、移动终端及消息推送系统
CN103139303A (zh) * 2013-02-07 2013-06-05 网易(杭州)网络有限公司 一种用于保持连接的心跳方法、装置及系统
CN103986740A (zh) * 2013-02-07 2014-08-13 中兴通讯股份有限公司 一种支持多终端应用的永远在线架构的方法及设备及系统
CN104767775A (zh) * 2014-01-06 2015-07-08 腾讯科技(深圳)有限公司 网页应用消息推送方法及系统
CN104144159A (zh) * 2014-06-26 2014-11-12 腾讯科技(深圳)有限公司 智能心跳保活方法及智能心跳保活系统

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111092809A (zh) * 2019-12-30 2020-05-01 北京每日优鲜电子商务有限公司 实时推送信息的方法、装置、计算机设备及存储介质
CN111092809B (zh) * 2019-12-30 2022-08-16 北京每日优鲜电子商务有限公司 实时推送信息的方法、装置、计算机设备及存储介质

Also Published As

Publication number Publication date
US20170134256A1 (en) 2017-05-11
AU2015400309B2 (en) 2020-07-09
US10263872B2 (en) 2019-04-16
CN105227398A (zh) 2016-01-06
CN105227398B (zh) 2018-09-04
AU2015400309A1 (en) 2017-03-23

Similar Documents

Publication Publication Date Title
WO2017041381A1 (zh) 多业务共享长连接方法、系统及其装置、终端
CN103069755B (zh) 使用多个客户端实例的即时消息传送的方法和系统
CN107181804B (zh) 资源的下载方法和装置
CN102457784B (zh) 在EPON+EoC网络中对EoC设备软件进行批量升级的方法
KR20050077688A (ko) 클라이언트 단말장치와 서버 사이의 세션 재설정을 위한시스템 및 방법
CN111510325B (zh) 报警信息推送方法、服务器、客户端及系统
RU2008138577A (ru) Сетевая система
CN104601702A (zh) 集群远程过程调用方法及系统
CN109474718A (zh) 域名解析方法和装置
CN109525620B (zh) 一种消息推送系统、方法及装置
WO2022068463A1 (en) Network node, terminal device, and methods therein for edge applications
WO2015027721A1 (zh) 一种终端状态订阅方法、装置及系统
CN113765774B (zh) 消息实时同步方法、装置、电子设备及介质
WO2013189398A2 (zh) 应用数据推送方法、装置及系统
CN102710810A (zh) 一种自动分配ip地址的方法及一种中继设备
CN104065656A (zh) 一种媒体流数据识别方法
CN104735401A (zh) 一种多个视频监控平台的统一网管方法
CN107370731B (zh) 基于自然语言实现不同应用之间通信的方法及装置
CN112839108B (zh) 连接建立方法、装置、设备、数据网络及存储介质
CN111726417B (zh) 延时控制方法、装置、服务器及存储介质
CN107395583B (zh) 基于自然语言实现不同应用之间通信的方法及装置
US10951501B1 (en) Monitoring availability of content delivery networks
CN111314492A (zh) 空调器及其数据传输方法和计算机可读存储介质
CN111092805A (zh) 基于dht网络的即时通信方法、装置、设备和介质
CN109996347B (zh) 一种建立终端设备之间连接的方法及装置

Legal Events

Date Code Title Description
ENP Entry into the national phase

Ref document number: 2015400309

Country of ref document: AU

Date of ref document: 20151218

Kind code of ref document: A

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 15903484

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15903484

Country of ref document: EP

Kind code of ref document: A1