CN109842647A - A kind of method, apparatus, system and medium maintaining long connection - Google Patents

A kind of method, apparatus, system and medium maintaining long connection Download PDF

Info

Publication number
CN109842647A
CN109842647A CN201711204124.1A CN201711204124A CN109842647A CN 109842647 A CN109842647 A CN 109842647A CN 201711204124 A CN201711204124 A CN 201711204124A CN 109842647 A CN109842647 A CN 109842647A
Authority
CN
China
Prior art keywords
random number
client
server
module
period
Prior art date
Legal status (The legal status 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 status listed.)
Pending
Application number
CN201711204124.1A
Other languages
Chinese (zh)
Inventor
章国琼
程宝平
李铎
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Mobile Communications Group Co Ltd
China Mobile Hangzhou Information Technology Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
China Mobile Hangzhou Information Technology Co Ltd
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 China Mobile Communications Group Co Ltd, China Mobile Hangzhou Information Technology Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN201711204124.1A priority Critical patent/CN109842647A/en
Publication of CN109842647A publication Critical patent/CN109842647A/en
Pending legal-status Critical Current

Links

Abstract

The invention discloses a kind of methods for maintaining long connection, device, system and medium, specifically: client generates random number within the period of setting, and the heartbeat data packets for carrying the random number are sent to server-side, and the random number is added in random number array, if receiving the heartbeat response data packet for carrying the random number of server-side return, then delete the random number in random number array, in this way, client can choose corresponding setting strategy according to the number of the random number in random number array, and the period is set according to the setting strategy of selection, rather than heartbeat data packets are sent according to the fixed period, it has been reduced as far as the transmission number of heartbeat data packets, alleviate the load of client and server-side, the electric quantity consumption of terminal device where reducing client.

Description

A kind of method, apparatus, system and medium maintaining long connection
Technical field
The present invention relates to field of communication technology more particularly to a kind of method, apparatus, system and media for maintaining long connection.
Background technique
In order to guarantee the duration of communication and the timeliness of data-pushing, lead between the client and server-side of application software It often needs to establish and maintains long connection.Currently, the method for the long connection of common maintenance client and server-side is client week Heartbeat data packets are sent to phase property to server-side, it is ensured that data transmission are always existed between client and server-side, to prevent connection It is automatically cut off by operator.This method for maintaining long connection not only increases network flow, also increases client and service The load at end, moreover, the electric quantity consumption that the frequent transmission of heartbeat data packets also results in client place terminal device is excessive.
In addition, from the performance and secure context of client consider, part client limit backstage periodic wakeup simultaneously The ability of heartbeat data packets is sent, in response to this, in the prior art, usually by server-side periodically to client Heartbeat data packets are sent to maintain long connection.This method for maintaining long connection has the following problems: if client is transported for a long time Row can automatically cut off the connection of client and server-side in the operating system of terminal device where backstage, client, to cause It connects unavailable, has been interrupted moreover, client can not perceive connection, and then also can not just carry out the automatic Reconstruction of long connection.
Summary of the invention
The embodiment of the invention provides a kind of method, apparatus, system and media for maintaining long connection, to solve existing skill Network flow consumption existing for the method for the long connection of maintenance in art is more, client and service end load is heavier and client institute In the more problem of the electric quantity consumption of terminal device, and solve when client long-play is at backstage, due to long connection It is automatically cut off by the operating system of terminal device where the client, causes to connect unavailable and since client can not the company of perception The problem of connecing and have been turned off, causing client that can not carry out the automatic Reconstruction of long connection.
Specific technical solution provided in an embodiment of the present invention is as follows:
A method of long connection is maintained, client is applied to, after being included in the long connection of client and server foundation, Following operation is executed in the period of setting:
Generate random number;
The heartbeat data packets for carrying random number are sent to server-side;
Random number is added to random number array;
If receiving the heartbeat response data packet for carrying random number of server-side return, delete in random number array Random number.
Preferably, setting the period in the following ways:
Based on the number of the random number in random number array, corresponding setting strategy, and the setting plan based on selection are chosen Slightly, the period is set.
Preferably, the number based on the random number in random number array, chooses corresponding setting strategy, and based on selection Setting strategy, sets the period, comprising:
It is first pre- by cycle set if the number of the random number in random number array is less than or equal to the first preset threshold If the period;
It was the second default week by cycle set if the number of the random number in random number array is greater than the first preset threshold Phase, wherein the first predetermined period is greater than the second predetermined period.
Preferably, by cycle set for after the second predetermined period, further includes:
If the number of the random number in random number array is less than or equal to the first preset threshold, by period from the second default week Phase adjusts to the first predetermined period;
If the number of the random number in random number array is greater than the first preset threshold, hold period was the second default week Phase;
If the number of the random number in random number array is more than or equal to the second preset threshold, suspends to server-side and send the heart Jump data packet.
Preferably, this method further include:
Receive the propelling data of third party's service end transparent transmission, wherein propelling data is the determining length with client of server-side Third party's service end is sent in the case where disconnecting;
Check whether the long connection with server-side has re-established;
If so, deleting propelling data;
If it is not, then showing propelling data, and re-establishes and connected with the long of server-side.
A method of long connection is maintained, server-side is applied to, after being included in server-side and the long connection of client's device foundation, Following operation is executed in the period of setting:
Receive the heartbeat data packets that client is sent;
Obtain the random number carried in heartbeat data packets;
Random number is carried and is back to client in heartbeat response data packet.
Preferably, this method further include:
Obtain the corresponding propelling data of client;
Check whether the long connection with client is interrupted;
If so, propelling data is sent to third party's service end, and pass through third party's service end for propelling data transparent transmission To client;
If it is not, propelling data is then sent to client.
A kind of device maintaining long connection, is applied to client, including generation module, sending module, adding module, and Removing module, wherein after client and server establishes long connection, generation module, sending module, adding module and deletion mould Block is respectively used to execute following operation within the period of setting:
Generation module, for generating random number;
Sending module, for sending the heartbeat data packets for carrying random number to server-side;
Adding module, for random number to be added to random number array;
Removing module, if the heartbeat response data packet for carrying random number for receiving server-side return, is deleted Random number in random number array.
Preferably, the device further includes setting module, wherein setting module for setting the period in the following ways:
Based on the number of the random number in random number array, corresponding setting strategy, and the setting plan based on selection are chosen Slightly, the period is set.
Preferably, choosing corresponding setting strategy, and be based on choosing in the number based on the random number in random number array Setting strategy, set the period when, setting module is specifically used for:
It is first pre- by cycle set if the number of the random number in random number array is less than or equal to the first preset threshold If the period;
It was the second default week by cycle set if the number of the random number in random number array is greater than the first preset threshold Phase, wherein the first predetermined period is greater than the second predetermined period.
Preferably, by cycle set be the second predetermined period after, setting module is also used to:
If the number of the random number in random number array is less than or equal to the first preset threshold, by period from the second default week Phase adjusts to the first predetermined period;
If the number of the random number in random number array is greater than the first preset threshold, hold period was the second default week Phase;
If the number of the random number in random number array is more than or equal to the second preset threshold, suspends to server-side and send the heart Jump data packet.
Preferably, the device further includes checking module, wherein check that module is used for:
Receive the propelling data of third party's service end transparent transmission, wherein propelling data is the determining length with client of server-side Third party's service end is sent in the case where disconnecting;
Check whether the long connection with server-side has re-established;
If so, deleting propelling data;
If it is not, then showing propelling data, and re-establishes and connected with the long of server-side.
A kind of device maintaining long connection, is applied to server-side, including receiving module, obtains module and return module, Wherein, after client and server establishes long connection, receiving module, acquisition module and return module are respectively used in setting Following operation is executed in period:
Receiving module, for receiving the heartbeat data packets of client transmission;
Module is obtained, for obtaining the random number carried in heartbeat data packets;
Return module is back to client in heartbeat response data packet for carrying random number.
Preferably, the device further includes checking module, wherein check that module is used for:
Obtain the corresponding propelling data of client;
Check whether the long connection with client is interrupted;
If so, propelling data is sent to third party's service end, and pass through third party's service end for propelling data transparent transmission To client;
If it is not, propelling data is then sent to client.
A kind of system maintaining long connection, device including the above-mentioned long connection of the maintenance applied to client and above-mentioned The device of the long connection of maintenance applied to server-side.
A kind of computer readable storage medium, the computer-readable recording medium storage have computer executable instructions, should The method that computer executable instructions are used to that computer to be made to execute the long connection of above-mentioned maintenance.
The embodiment of the present invention has the beneficial effect that:
In the embodiment of the present invention, when carrying the heartbeat data packets of random number to server-side transmission, which is added Add in random number array, receive server-side return the heartbeat response data packet for carrying the random number when, delete with Random number in machine number array, in this way, client can be chosen accordingly according to the number of the random number in random number array Setting strategy, and the period is set according to the setting strategy of selection, rather than send heartbeat data packets according to the fixed period, It has been reduced as far as the transmission number of heartbeat data packets, the load of client and server-side has been alleviated, reduces network flow With the consumption of the electricity of terminal device where client.
Further, when the long disconnecting of server-side determination and client, the propelling data of the client is sent to Third party's client, and by the third party's service end transparent transmission propelling data, Lai Huanqi client re-establishes long connection, thus Realize the automatic Reconstruction of long connection.
Detailed description of the invention
Fig. 1 is the overview schematic diagram of the method provided in an embodiment of the present invention for maintaining long connection;
Fig. 2 is the idiographic flow schematic diagram of the method provided in an embodiment of the present invention for maintaining long connection;
Fig. 3 is the method provided in an embodiment of the present invention for re-establishing long connection automatically during maintaining long connection Flow diagram;
Fig. 4 is the illustrative view of functional configuration of the device provided in an embodiment of the present invention for maintaining long connection;
Fig. 5 is the illustrative view of functional configuration of the device provided in an embodiment of the present invention for maintaining long connection.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete Site preparation description, it is clear that described embodiments are only a part of the embodiments of the present invention, is not whole embodiments.It is based on Embodiment in the present invention, it is obtained by those of ordinary skill in the art without making creative efforts every other Embodiment shall fall within the protection scope of the present invention.
In order to solve the method in the prior art for maintaining long connection network flow consumption is more, client and service The heavier problem more with the electric quantity consumption of terminal device where client of end load, and solve to work as client long-play At backstage, since the operating system of terminal device is automatically cut off where the client for long connection, cause to connect it is unavailable and Due to the problem of client, which can not perceive connection, to be had been turned off, cause client that can not carry out the automatic Reconstruction of long connection, the present invention In embodiment, after client and server-side establish long connection, client generates random number within the period of setting, and to clothes Business end sends the heartbeat data packets for carrying the random number, and the random number is added in random number array, if receiving The heartbeat response data packet for carrying the random number that server-side returns, then delete the random number in random number array, in this way, Client can choose corresponding setting strategy according to the number of the random number in random number array, and according to the setting of selection Strategy sets the period, rather than according to the fixed period sends heartbeat data packets, has been reduced as far as heartbeat data packets Number is sent, the load of client and server-side is alleviated, the electricity of terminal device where reducing network flow and client Consumption, moreover, the propelling data of the client is sent to third party when the server-side determining long disconnecting with client Client, and by the third party's service end transparent transmission propelling data, Lai Huanqi client re-establishes long connection, to realize The automatic Reconstruction of long connection.
The present invention program is described in detail below by specific embodiment, certainly, the present invention is not limited to following realities Apply example.
In practical applications, client and server-side establish long connection in the following ways:
Firstly, client, which sends long connection to server-side, establishes request, wherein length connection, which is established in request, carries mirror Weigh information.
Then, request is established in the long connection that server-side receives that client is sent, and is connected to establish in request to the length and be carried Authentication information authenticated, if the authentication is passed, establish long connection with client, and return to long connection to client and establish and ring It answers.
Finally, assert that the long connection with server-side is built when client receives the long connection establishment response of server-side return It stands successfully.
Further, it after the long connection of client and server-side is successfully established, can be mentioned using the embodiment of the present invention Confession maintains the method for long connection to maintain long connection, specifically, as shown in fig.1, the process of the method for the long connection of the maintenance To execute following steps within the period of setting:
Step 101: client generates random number.
Step 102: client sends the heartbeat data packets for carrying the random number to server-side.
Step 103: the random number is added in random number array by client.
Step 104: server-side receives the heartbeat data packets that client is sent.
Step 105: server-side obtains the random number carried in the heartbeat data packets.
Step 106: server-side returns to the heartbeat response data packet for carrying the random number to client.
Step 107: if client receives the heartbeat response data packet for carrying the random number of server-side return, deleting Except the random number in random number array.
In this way, client can choose corresponding setting strategy according to the number of the random number in random number array, and The period is set according to the setting strategy of selection, rather than sends heartbeat data packets according to fixed sending cycle, as much as possible The transmission number for reducing heartbeat data packets, alleviates the load of client and server-side, reduces network flow and client The consumption of the electricity of place terminal device.
Specifically, number of the client based on the random number in random number array is chosen corresponding setting strategy, and is based on The setting strategy of selection can use when setting the period but be not limited to following manner:
It is first pre- by cycle set if the number of the random number in random number array is less than or equal to the first preset threshold If the period;It was the second default week by cycle set if the number of the random number in random number array is greater than the first preset threshold Phase, wherein the first predetermined period is greater than the second predetermined period.
It is tellable to be, when the number of the random number in random number array is less than or equal to the first preset threshold, can recognize Determine network and long connection be relatively normal, service can normal use, at this point it is possible to by being the first predetermined period by cycle set Mode, reduces the transmission number of heartbeat data packets, to alleviate the load of client and server-side, reduce network flow and The consumption of the electricity of terminal device where client.And when the number of the random number in random number array is greater than the first preset threshold When, it can be assumed that client does not receive the heartbeat response data packet of server-side return at least once, such case may be As caused by the reasons such as network is not good enough, can not directly assert long connection interrupted and/or serviced it is unavailable, at this point, client It can quickly determine in time whether long connection is interrupted and/or serviced by way of being the second predetermined period by cycle set Whether can be used, specifically, client can use but be not limited to following manner:
If the number of the random number in random number array is less than or equal to the first preset threshold, by period from the second default week Phase adjusts to the first predetermined period;If the number of the random number in random number array is greater than the first preset threshold, hold period For the second predetermined period;If the number of the random number in random number array is more than or equal to the second preset threshold, suspend to service End sends heartbeat data packets.
It is tellable to be, when the number of the random number in random number array is less than or equal to the first preset threshold, can recognize Determine client do not receive at least once server-side return heartbeat response data packet be as caused by the reasons such as network is not good enough, And network has restored normally at this time, can adjust by the period from the second predetermined period to the first predetermined period, subtracts The transmission number of few heartbeat data packets reduces network flow and client to alleviate the load of client and server-side The consumption of the electricity of place terminal device;It, can be with when the number of the random number in random number array is greater than the first preset threshold Assert that network does not restore normally, to need to send heartbeat data packets to server-side further according to the second predetermined period, until random The number of random number in number arrays is more than or equal to the second preset threshold, and assert long connection interrupted and/or serviced it is unavailable, At this point it is possible to the transmission number of heartbeat data packets be reduced, to subtract by way of suspending and sending heartbeat data packets to server-side The light load of client and server-side, the consumption of the electricity of terminal device where reducing network flow and client.
Below only with " for the first predetermined period for 120 seconds, the second predetermined period was 10 seconds, and the first preset threshold is 0, second It is that concrete application scene is described in further detail above-described embodiment that preset threshold, which is 3 ", in the embodiment of the present invention, in client End and server-side are built after long connection, can be the first predetermined period by cycle set, specifically, as shown in fig.2, maintaining length The detailed process of the method for connection is as follows:
Step 201: client sends long connection to server-side and establishes request, wherein length connection, which is established in request, to be carried There is authentication information.
Step 202: server-side receives the long connection that client is sent and establishes request, and connects to establish in request to the length and take The authentication information of band is authenticated.
Step 203: server-side establishes long connection when determining that the authentication is passed, with client, and returns to long connect to client Connect foundation response.
Step 204: when client receives the long connection establishment response of server-side return, assert and connected with the long of server-side It is successfully established.
Step 205: when client determines arrival 120 seconds, generating random number.
Step 206: client sends the heartbeat data packets for carrying the random number to server-side.
Step 207: the random number is added in random number array by client.
Step 208: server-side receive client send heartbeat data packets, and obtain carried in the heartbeat data packets with Machine number.
Step 209: server-side returns to the heartbeat response data packet for carrying the random number to client.
Step 210: if client receives the heartbeat response data packet for carrying the random number of server-side return, deleting Except the random number in random number array.
Step 211: client judges whether the number of the random number in random number array is greater than 0;If so, thening follow the steps 212;If it is not, then return step 205.
Step 212: client adjusted the period to 10 seconds from 120 seconds.
Step 213: when client determines arrival 10 seconds, generating random number, and execute step 206- step 210.
Step 214: client judges whether the number of the random number in random number array is greater than 0;If so, thening follow the steps 215;If it is not, thening follow the steps 217.
Step 215: client judges whether the number of the random number in random number array is more than or equal to 3;If so, executing Step 216;If it is not, then return step 213.
Step 216: client, which is suspended to server-side, sends heartbeat data packets.
Step 217: client adjusted the period to 120 seconds from 10 seconds.
Further, in order to ensure client can perceive long disconnecting, the automatic Reconstruction of long connection, server-side are realized Before sending the corresponding propelling data of the client to client every time, by checking in the long connection whether with the client It is disconnected, and in the case where the determining long connection with the client has been interrupted, it is using third party's service end transparent transmission that propelling data is saturating The mode of client is reached, Lai Huanqi client re-establishes long connection, specifically, as shown in fig.3, maintaining long connection The process for re-establishing the method for long connection automatically in the process is as follows:
Step 301: server-side obtains the corresponding propelling data of client.
Step 302: whether server-side inspection and the long connection of client are interrupted;If so, thening follow the steps 303;If it is not, then Execute step 308.
Step 303: propelling data is sent to third party's service end by server-side, and will push number by third party's service end According to being pass-through to client.
Preferably, which can be in the clothes that the client is resided on the terminal device for corresponding service Business end, specifically, the server-side of terminal device itself where can be but being not limited to client, for example, millet Push Service End, Huawei's Push Service end etc..
Step 304: the propelling data of client reception third party's service end transparent transmission.
Step 305: whether client inspection and the long connection of server-side have re-established;If so, thening follow the steps 306; If it is not, thening follow the steps 307.
Step 306: client deletes propelling data.
Step 307: client shows propelling data, and re-establishes and connect with the long of server-side.
Step 308: propelling data is sent to client by server-side.
Step 309: client receives the propelling data that server-side is sent, and shows propelling data.
Tellable to be, user may re-establish long connection by client, and clothes have been received in client The propelling data of business end transmission simultaneously has been displayed to user, but due to network delay etc., the push of third party's service end transparent transmission Data delay is sent to, so, client needs inspection and server-side after the propelling data for receiving third party's service end transparent transmission Long connection whether re-established, when determining that long connection has re-established, propelling data is deleted, so as to avoid push number According to repetition show.
Based on the same inventive concept, the embodiment of the invention provides a kind of device for maintaining long connection, it is applied to client, As shown in fig.4, the device of the long connection of the maintenance includes at least generation module 401, and sending module 402, adding module 403, with And removing module 404, wherein after client and server establishes long connection, generation module 401, sending module 402, addition Module 403 and removing module 404 are respectively used to execute following operation within the period of setting:
Generation module 401, for generating random number;
Sending module 402, for sending the heartbeat data packets for carrying random number to server-side;
Adding module 403, for random number to be added to random number array;
Removing module 404, if receiving the heartbeat response for carrying random number of server-side return for receiving module 405 Data packet then deletes the random number in random number array.
Preferably, the device of the long connection of the maintenance further includes setting module 406, wherein setting module 406 for use with Under type sets the period:
Based on the number of the random number in random number array, corresponding setting strategy, and the setting plan based on selection are chosen Slightly, the period is set.
Preferably, choosing corresponding setting strategy, and be based on choosing in the number based on the random number in random number array Setting strategy, set the period when, setting module 406 is specifically used for:
It is first pre- by cycle set if the number of the random number in random number array is less than or equal to the first preset threshold If the period;
It was the second default week by cycle set if the number of the random number in random number array is greater than the first preset threshold Phase, wherein the first predetermined period is greater than the second predetermined period.
Preferably, by cycle set be the second predetermined period after, setting module 406 is also used to:
If the number of the random number in random number array is less than or equal to the first preset threshold, by period from the second default week Phase adjusts to the first predetermined period;
If the number of the random number in random number array is greater than the first preset threshold, hold period was the second default week Phase;
If the number of the random number in random number array is more than or equal to the second preset threshold, suspends to server-side and send the heart Jump data packet.
Preferably, the device of the long connection of the maintenance further includes checking module 407, wherein check that module 407 is used for:
Receive the propelling data of third party's service end transparent transmission, wherein propelling data is the determining length with client of server-side Third party's service end is sent in the case where disconnecting;
Check whether the long connection with server-side has re-established;
If so, deleting propelling data;
If it is not, then showing propelling data, and re-establishes and connected with the long of server-side.
Based on the same inventive concept, the embodiment of the invention also provides another device for maintaining long connection, it is applied to clothes It is engaged in end, as shown in fig.5, the device of the long connection of the maintenance includes at least receiving module 501, acquisition module 502, and returning to mould Block 503, wherein after client and server establishes long connection, receiving module 501 obtains module 502 and return module 503 It is respectively used to execute following operation within the period of setting:
Receiving module 501, for receiving the heartbeat data packets of client transmission;
Module 502 is obtained, for obtaining the random number carried in heartbeat data packets;
Return module 503 is back to client in heartbeat response data packet for carrying random number.
Preferably, the device of the long connection of the maintenance further includes checking module 504, wherein check that module 504 is used for:
Obtain the corresponding propelling data of client;
Check whether the long connection with client is interrupted;
If so, propelling data is sent to third party's service end, and pass through third party's service end for propelling data transparent transmission To client;
If it is not, propelling data is then sent to client.
Based on the above embodiment, the embodiment of the invention provides a kind of system for maintaining long connection, maintenance length is connected System includes at least: the device of the long connection of the above-mentioned maintenance applied to client and the above-mentioned maintenance applied to server-side are long The device of connection.
After describing the methods, devices and systems of exemplary embodiment of the invention, next, to example of the present invention Property embodiment for maintaining the long computer readable storage medium connected to be introduced.The embodiment of the invention provides one kind Computer readable storage medium, the computer-readable recording medium storage have computer executable instructions, and the computer is executable Instruct the method for making computer execute the long connection of above-mentioned maintenance.
In conclusion after the long connection of client and server-side is successfully established, client is being set in the embodiment of the present invention Random number is generated in fixed period, and sends the heartbeat data packets for carrying the random number to server-side, and by the random number It is added in random number array, if receiving the heartbeat response data packet for carrying the random number of server-side return, deletes Random number in random number array, in this way, client can choose phase according to the number of the random number in random number array The setting strategy answered, and the period is set according to the setting strategy of selection, rather than heartbeat data is sent according to the fixed period Packet, has been reduced as far as the transmission number of heartbeat data packets, has alleviated the load of client and server-side, reduce network flow The consumption of the electricity of terminal device where amount and client, moreover, when server-side determination and the long disconnecting of client, by this The propelling data of client is sent to third party's client, and by the third party's service end transparent transmission propelling data, to arouse visitor Family end re-establishes long connection, to realize the automatic Reconstruction of long connection.
It should be understood by those skilled in the art that, the embodiment of the present invention can provide as method, system or computer program Product.Therefore, complete hardware embodiment, complete software embodiment or reality combining software and hardware aspects can be used in the present invention Apply the form of example.Moreover, it wherein includes the computer of computer usable program code that the present invention, which can be used in one or more, The computer program implemented in usable storage medium (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) produces The form of product.
The present invention be referring to according to the method for the embodiment of the present invention, the process of equipment (system) and computer program product Figure and/or block diagram describe.It should be understood that every one stream in flowchart and/or the block diagram can be realized by computer program instructions The combination of process and/or box in journey and/or box and flowchart and/or the block diagram.It can provide these computer programs Instruct the processor of general purpose computer, special purpose computer, Embedded Processor or other programmable data processing devices to produce A raw machine, so that being generated by the instruction that computer or the processor of other programmable data processing devices execute for real The device for the function of being specified in present one or more flows of the flowchart and/or one or more blocks of the block diagram.
These computer program instructions, which may also be stored in, is able to guide computer or other programmable data processing devices with spy Determine in the computer-readable memory that mode works, so that it includes referring to that instruction stored in the computer readable memory, which generates, Enable the manufacture of device, the command device realize in one box of one or more flows of the flowchart and/or block diagram or The function of being specified in multiple boxes.
These computer program instructions also can be loaded onto a computer or other programmable data processing device, so that counting Series of operation steps are executed on calculation machine or other programmable devices to generate computer implemented processing, thus in computer or The instruction executed on other programmable devices is provided for realizing in one or more flows of the flowchart and/or block diagram one The step of function of being specified in a box or multiple boxes.
Although preferred embodiments of the present invention have been described, it is created once a person skilled in the art knows basic Property concept, then additional changes and modifications may be made to these embodiments.So it includes excellent that the following claims are intended to be interpreted as It selects embodiment and falls into all change and modification of the scope of the invention.
Obviously, those skilled in the art can carry out various modification and variations without departing from this hair to the embodiment of the present invention The spirit and scope of bright embodiment.In this way, if these modifications and variations of the embodiment of the present invention belong to the claims in the present invention And its within the scope of equivalent technologies, then the present invention is also intended to include these modifications and variations.

Claims (16)

1. a kind of method for maintaining long connection, is applied to client, which is characterized in that be included in the client and server and build After vertical long connection, following operation is executed within the period of setting:
Generate random number;
The heartbeat data packets for carrying the random number are sent to the server-side;
The random number is added to random number array;
If receiving the heartbeat response data packet for carrying the random number that the server-side returns, the random number is deleted The random number in array.
2. the method as described in claim 1, which is characterized in that including setting the period in the following ways:
Based on the number of the random number in the random number array, corresponding setting strategy is chosen, and based on setting described in selection Fixed strategy, sets the period.
3. method according to claim 2, which is characterized in that the number based on the random number in the random number array, choosing Corresponding setting strategy, and the setting strategy based on selection are taken, the period is set, comprising:
It is the by the cycle set if the number of the random number in the random number array is less than or equal to the first preset threshold One predetermined period;
It is the by the cycle set if the number of the random number in the random number array is greater than first preset threshold Two predetermined periods, wherein first predetermined period is greater than second predetermined period.
4. method as claimed in claim 3, which is characterized in that by the cycle set be the second predetermined period after, also wrap It includes:
If the number of the random number in the random number array is less than or equal to first preset threshold, by the period from institute The second predetermined period is stated to adjust to first predetermined period;
If the number of the random number in the random number array is greater than first preset threshold, it is described for being kept for the period Second predetermined period;
If the number of the random number in the random number array is more than or equal to the second preset threshold, suspends and sent out to the server-side Send heartbeat data packets.
5. method according to any of claims 1-4, which is characterized in that further include:
Receive the propelling data of third party's service end transparent transmission, wherein the propelling data is the server-side determination and the visitor The third party's service end is sent in the case where the long disconnecting at family end;
Check whether the long connection with the server-side has re-established;
If so, deleting the propelling data;
If it is not, then showing the propelling data, and re-establishes and connected with the long of the server-side.
6. a kind of method for maintaining long connection, is applied to server-side, which is characterized in that be included in the server-side and client's device is built After vertical long connection, following operation is executed within the period of setting:
Receive the heartbeat data packets that the client is sent;
Obtain the random number carried in the heartbeat data packets;
Random number carrying is back to the client in heartbeat response data packet.
7. method as claimed in claim 6, which is characterized in that further include:
Obtain the corresponding propelling data of the client;
Check whether the long connection with the client is interrupted;
If so, the propelling data is sent to third party's service end, and by the third party's service end by the push Data penetration transmission is to the client;
If it is not, the propelling data is then sent to the client.
8. a kind of device for maintaining long connection, is applied to client, which is characterized in that including generation module, sending module, addition Module and removing module, wherein after the client and server establishes long connection, the generation module, the transmission Module, the adding module and removing module are respectively used to execute following operation within the period of setting:
The generation module, for generating random number;
The sending module, for sending the heartbeat data packets for carrying the random number to the server-side;
The adding module, for the random number to be added to random number array;
The removing module, if the heartbeat response data for carrying the random number returned for receiving the server-side Packet, then delete the random number in the random number array.
9. device as claimed in claim 8, which is characterized in that further include setting module, wherein the setting module is for adopting The period is set with the following methods:
Based on the number of the random number in the random number array, corresponding setting strategy is chosen, and based on setting described in selection Fixed strategy, sets the period.
10. device as claimed in claim 9, which is characterized in that in the number based on the random number in the random number array, Corresponding setting strategy, and the setting strategy based on selection are chosen, when setting the period, the setting module is specifically used In:
It is the by the cycle set if the number of the random number in the random number array is less than or equal to the first preset threshold One predetermined period;
It is the by the cycle set if the number of the random number in the random number array is greater than first preset threshold Two predetermined periods, wherein first predetermined period is greater than second predetermined period.
11. device as claimed in claim 10, which is characterized in that by the cycle set be the second predetermined period after, The setting module is also used to:
If the number of the random number in the random number array is less than or equal to first preset threshold, by the period from institute The second predetermined period is stated to adjust to first predetermined period;
If the number of the random number in the random number array is greater than first preset threshold, it is described for being kept for the period Second predetermined period;
If the number of the random number in the random number array is more than or equal to the second preset threshold, suspends and sent out to the server-side Send heartbeat data packets.
12. such as the described in any item devices of claim 8-11, which is characterized in that further include checking module, wherein the inspection Module is used for:
Receive the propelling data of third party's service end transparent transmission, wherein the propelling data is the server-side determination and the visitor The third party's service end is sent in the case where the long disconnecting at family end;
Check whether the long connection with the server-side has re-established;
If so, deleting the propelling data;
If it is not, then showing the propelling data, and re-establishes and connected with the long of the server-side.
13. a kind of device for maintaining long connection, is applied to server-side, which is characterized in that including receiving module, module is obtained, with And return module, wherein after the client and server establishes long connection, the receiving module, the acquisition module and The return module is respectively used to execute following operation within the period of setting:
The receiving module, the heartbeat data packets sent for receiving the client;
The acquisition module, for obtaining the random number carried in the heartbeat data packets;
The return module, for random number carrying to be back to the client in heartbeat response data packet.
14. device as claimed in claim 13, which is characterized in that further include checking module, wherein the inspection module is used In:
Obtain the corresponding propelling data of the client;
Check whether the long connection with the client is interrupted;
If so, the propelling data is sent to third party's service end, and by the third party's service end by the push Data penetration transmission is to the client;
If it is not, the propelling data is then sent to the client.
15. a kind of system for maintaining long connection, which is characterized in that including such as described in any item devices of claim 8-12, with And such as the described in any item devices of claim 13-14.
16. a kind of computer readable storage medium, which is characterized in that the computer-readable recording medium storage has computer can Execute instruction, the computer executable instructions for executing the computer as right wants the described in any item methods of 1-5, Or execute such as the described in any item methods of claim 6-7.
CN201711204124.1A 2017-11-27 2017-11-27 A kind of method, apparatus, system and medium maintaining long connection Pending CN109842647A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711204124.1A CN109842647A (en) 2017-11-27 2017-11-27 A kind of method, apparatus, system and medium maintaining long connection

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711204124.1A CN109842647A (en) 2017-11-27 2017-11-27 A kind of method, apparatus, system and medium maintaining long connection

Publications (1)

Publication Number Publication Date
CN109842647A true CN109842647A (en) 2019-06-04

Family

ID=66880024

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711204124.1A Pending CN109842647A (en) 2017-11-27 2017-11-27 A kind of method, apparatus, system and medium maintaining long connection

Country Status (1)

Country Link
CN (1) CN109842647A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111180031A (en) * 2019-12-31 2020-05-19 贵州精准健康数据有限公司 Data management system and method
CN113676487A (en) * 2021-08-31 2021-11-19 中国电信股份有限公司 Port connection control method, management method, device and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101695171A (en) * 2009-10-16 2010-04-14 中兴通讯股份有限公司 Method utilizing stream control transmission protocol to measure network transmission quality and device thereof
CN105610913A (en) * 2015-12-22 2016-05-25 用友网络科技股份有限公司 Heartbeat keep-alive method and apparatus for long connection in communication network
CN106789394A (en) * 2016-11-18 2017-05-31 上海斐讯数据通信技术有限公司 A kind of connection server keep Alive Packet control method long and system
CN106803833A (en) * 2015-11-26 2017-06-06 北京百度网讯科技有限公司 Processing method, the apparatus and system of heartbeat in connection long
US20170171518A1 (en) * 2015-12-15 2017-06-15 BOT Home Automation, Inc. Video on demand for audio/video recording and communication devices

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101695171A (en) * 2009-10-16 2010-04-14 中兴通讯股份有限公司 Method utilizing stream control transmission protocol to measure network transmission quality and device thereof
CN106803833A (en) * 2015-11-26 2017-06-06 北京百度网讯科技有限公司 Processing method, the apparatus and system of heartbeat in connection long
US20170171518A1 (en) * 2015-12-15 2017-06-15 BOT Home Automation, Inc. Video on demand for audio/video recording and communication devices
CN105610913A (en) * 2015-12-22 2016-05-25 用友网络科技股份有限公司 Heartbeat keep-alive method and apparatus for long connection in communication network
CN106789394A (en) * 2016-11-18 2017-05-31 上海斐讯数据通信技术有限公司 A kind of connection server keep Alive Packet control method long and system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111180031A (en) * 2019-12-31 2020-05-19 贵州精准健康数据有限公司 Data management system and method
CN113676487A (en) * 2021-08-31 2021-11-19 中国电信股份有限公司 Port connection control method, management method, device and storage medium

Similar Documents

Publication Publication Date Title
CN108023953B (en) High-availability implementation method and device for FTP service
CN108647089A (en) Resource allocation method, device, terminal and storage medium
CN106303648A (en) A kind of method and device synchronizing to play multi-medium data
CN104702665B (en) Information sharing method and information sharing apparatus
US10623193B2 (en) Enhancing collaboration in real-time group chat system and method
JP5624224B2 (en) Data providing system, providing device, execution device, control method, program, and recording medium
CN105871977A (en) Long connection establishment method and system, and devices
CN110765744A (en) Multi-person collaborative document editing method and system
CN105262911B (en) The processing method, system and device of system telephone in voice communication
CN106331155B (en) A kind of method preventing user's repeat logon and server
CN108650667A (en) Terminal scheduling method and apparatus
CN111083177B (en) Cross-domain collaborative interaction method based on collaborative gateway
CN111510493B (en) Distributed data transmission method and device
CN109842647A (en) A kind of method, apparatus, system and medium maintaining long connection
CN105635124A (en) Flow control method and device
CN109089288A (en) A kind of method and apparatus of data transmission
CN113079139B (en) Block chain-based consensus group master node determination method, device and system
CN104580095A (en) API resource acquisition method and device
CN106657172A (en) Method and device for realizing information push
CN104683217A (en) Multimedia information transmission method and instant messaging client
CN103916823A (en) Method and apparatus for creating mobile conference call
CN111654526A (en) Load balancing method and system for streaming media server
CN110233791A (en) Data duplicate removal method and device
CN105681262A (en) Interaction message allocating method and system
CN105872756A (en) Method, device and system for sharing television playing information

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20190604