Establish the method, apparatus and system of long connection
Technical field
The present invention relates to a kind of Internet technical fields, more particularly to a kind of method, apparatus for establishing long connection and are
System.
Background technique
In LAN environment, is typically set up between server and terminal and keep transmission control protocol
(Transmission Control Protocol, TCP) long connection, it can be ensured that server is timely by mission dispatching to eventually
End, terminal receive and respond the task.
But in actual scene, server can't issue assignment instructions to terminal in real time, in the most of the time, TCP
Long connection is at idle state, occupies valuable network transmission resource.For larger local area network, build
It stands and keeps thousands of TCP long connections that can cause biggish load pressure to network, may result under extreme case whole
The paralysis of a local area network.
Summary of the invention
In view of this, the embodiment of the present invention provides a kind of method, apparatus and system for establishing long connection, main purpose is
Solve the problems, such as that long connection occupies Internet resources.
According to the present invention on one side, a kind of method for establishing long connection is provided, comprising:
Long connection is established with terminal;
Assignment instructions are issued to terminal by long connection, so that terminal executes corresponding task according to assignment instructions;
After terminal has executed task, the long connection established with terminal is disconnected.
According to another aspect of the present invention, the device for establishing long connection is provided, comprising:
Unit is established, for establishing long connection with terminal;
Issuance unit issues assignment instructions to terminal for the long connection by establishing unit foundation, so as to terminal according to
Assignment instructions execute corresponding task;
Switching units, for after the task that terminal has executed that issuance unit issues, disconnecting the long connection established with terminal.
According to another aspect of the present invention, the system for establishing long connection, including terminal and server are provided, wherein eventually
End includes device as described above.
By above-mentioned technical proposal, the method, apparatus and system provided by the invention for establishing connection is based on server and end
The long connection that end is established, server are connected to terminal by the length and issue assignment instructions, and terminal receives the assignment instructions and basis
The assignment instructions go to execute corresponding task, disconnect the long connection established with server after having executed task.With prior art phase
Than in the present invention, terminal can select the best opportunity for establishing long connection with server according to the demand of itself, and can be with
After the task that terminal has executed that server issues, the long connection established with server is interrupted, this kind of mode reduces server
The Internet resources occupied when long connection are always maintained at terminal.
The above description is only an overview of the technical scheme of the present invention, in order to better understand the technical means of the present invention,
And it can be implemented in accordance with the contents of the specification, and in order to allow above and other objects of the present invention, feature and advantage can
It is clearer and more comprehensible, the followings are specific embodiments of the present invention.
Detailed description of the invention
By reading the following detailed description of the preferred embodiment, various other advantages and benefits are common for this field
Technical staff will become clear.The drawings are only for the purpose of illustrating a preferred embodiment, and is not considered as to the present invention
Limitation.And throughout the drawings, the same reference numbers will be used to refer to the same parts.In the accompanying drawings:
Fig. 1 shows a kind of flow chart of method for establishing long connection provided in an embodiment of the present invention;
Fig. 2 shows a kind of composition block diagrams for the device for establishing long connection provided in an embodiment of the present invention;
Fig. 3 shows a kind of composition block diagram of system for establishing long connection provided in an embodiment of the present invention.
Specific embodiment
Exemplary embodiments of the present disclosure are described in more detail below with reference to accompanying drawings.Although showing the disclosure in attached drawing
Exemplary embodiment, it being understood, however, that may be realized in various forms the disclosure without should be by embodiments set forth here
It is limited.On the contrary, these embodiments are provided to facilitate a more thoroughly understanding of the present invention, and can be by the scope of the present disclosure
It is fully disclosed to those skilled in the art.
The embodiment of the invention provides a kind of method, apparatus and system for establishing long connection, as shown in Figure 1, this method packet
It includes:
101, long connection is established with terminal.
During the actual network operation, terminal needs to send the solicited message for establishing short connection, service to server
After device receives the solicited message, determine that establishing network communication with terminal connect.It establishes after network communication connection, server
It is communicated with terminal, in communication process, when server discovery has data packet to need to be handed down to terminal, server can be to end
End sends the instruction information for establishing long connection, after the instruction information for the long connection of foundation that terminal receives server transmission, eventually
The solicited message for sending to server and establishing long connection is held, establishes long connection with service.In the embodiment of the present invention, server and end
It is unimpeded that the long connection that end is established can not only maintain the network communication between server and terminal connect, but also work as and have data packet
When needing to issue, server can be connected to terminal based on the length and issue data packet in time.
Optionally, can also be before terminal and server carry out network communication connection, terminal to server is direct
The solicited message for establishing long connection is sent, it is determining to establish long connection with terminal after server receives the solicited message.About
Server and terminal establish the realization process of long connection, and it is not limited by the embodiments of the present invention.
102, assignment instructions are issued to terminal by long connection, so that terminal executes corresponding task according to assignment instructions.
After above-mentioned steps 101 and terminal establish long connection, server can be connected to terminal by the length and issue task
Instruction parses the assignment instructions after terminal receives assignment instructions, obtains the task that simultaneously execute server issues.Wherein,
Carry system or application program updating in assignment instructions, patch reparation updates, unloading etc., about carrying in assignment instructions
The contents of specific tasks set according to the actual situation, the specific embodiment of the present invention is to this without limiting.
When server, which has new assignment instructions to need to be handed down to terminal, to be executed, server not necessarily immediately will be new
Assignment instructions are handed down to terminal, after server can also be obtained other a part of new task instructions after a period of time, then will obtain
The assignment instructions taken are handed down to terminal, so that carrying more assignment instructions for being directed to different task in assignment instructions.This
In inventive embodiments, when server to terminal issue assignment instructions be it is multiple when, can first to terminal send multiple tasks instruction
One of assignment instructions issue other assignment instructions to terminal again after waiting terminal to respond the assignment instructions;Or
It is all sent to terminal using by the multiple tasks instruction of server end, which terminal responds according to the demand of itself selection first
Assignment instructions.Specifically issuing the modes of assignment instructions to terminal about server, it is not limited by the embodiments of the present invention.
Optionally, terminal parses assignment instructions, can by but be not limited to mode below and realize, for example,
Terminal parses the content carried in assignment instructions one by one, after obtaining all tasks carried in the assignment instructions, eventually
End is gone to execute all tasks obtained again;Alternatively, the content that terminal carries assignment instructions parses, assignment instructions are parsed
In entrained one of task, and the task is executed, after having executed the task, entrained by continuing to parse in assignment instructions
Other tasks, repeatedly, until having parsed all tasks carried in assignment instructions.Wherein, about logical to task
The resolving of instruction, it is not limited by the embodiments of the present invention.
103, after terminal has executed task, the long connection established with terminal is disconnected.
After terminal has executed corresponding task according to assignment instructions, being not carried out for task is checked for, if it exists not
The task of execution then continues to execute the task that server issues;Being not carried out if it does not exist for task is then disconnected and being established with server
Long connection.In this step, in order to reduce the occupancy of Internet resources, while the assignment instructions usual situation that server issues
Under be it is disposable effective, terminal disconnects the long connection established with server after having executed the task that server issues.
The method provided in an embodiment of the present invention for establishing connection, based on the long connection that server and terminal are established, server
It is connected by the length to terminal and issues assignment instructions, terminal receives the assignment instructions and goes to execute according to the assignment instructions corresponding
Task disconnects the long connection established with server after having executed task.Compared with prior art, in the present invention, terminal can root
The best opportunity of long connection is established with server according to the demand selection of itself, and server can also have been executed in terminal and issued
Task after, interrupt with server establish it is long connect, this kind of mode reduces server and when terminal is always maintained at long connection
The Internet resources of occupancy.
In the implementation process that step 101 and terminal establish long connection, long connection is kept to occupy in order to further reduce
Internet resources disconnect the short connection established with terminal in time after server and terminal establish long connection;It has been executed in terminal
After the task that server issues, the long connection established with server is disconnected, and establish asking for short connection to server transmission again
After asking information, server to receive the solicited message, determine that establishing network communication with terminal connect.Wherein, terminal again with
The purpose that server establishes short connection is that the synchronism of holding server and terminal data, terminal can be sent out to server timing
Heartbeat message is sent, to determine when server has task to issue to terminal, server can send in time to terminal and establish long connect
The instruction information connect.Wherein, the period that terminal to server regularly sends heartbeat message is rule of thumb set, for example, can
Setting terminal sent a heartbeat message to server every 5 seconds, can also be sent out every 10 seconds to server with setting terminal
A heartbeat message is sent, to ensure the synchronism of data between terminal and server.Specifically the heart is sent about terminal to server
The period of message is jumped, it is not limited by the embodiments of the present invention.
In another embodiment of the present invention, when terminal and server establish long connection, when needing to select suitable
Machine, it is ensured that the Internet resources for maintaining long connection to occupy should be reduced, ensure that the task of server end can be handed down in time again
Terminal.Wherein, the opportunity that selection terminal and server establish long connection can be by different modes, below by following seven kinds of sides
Formula describes in detail:
Mode one:
Timing establishes long connection with terminal.
Timing mentioned here and terminal establish long connection should be establish network communication connection in terminal and server, and
It keeps realizing on the basis of terminal and server data are synchronous.Illustratively, after setting timing establishes long connection with terminal, clothes
Business device can establish long connection according to the timing cycle pre-set with terminal automatically, and after establishing long connection, server can be examined
Looking into its own whether there is the assignment instructions for needing terminal to execute;If it exists, then it is connected based on the length and issues task to terminal and refer to
It enables.Wherein, the period of the timing is rule of thumb, is manually set, for example, the period of setting timing be half an hour, it is one small
When;Alternatively, the period that timing can be set is ten minutes, 20 minutes.The period embodiment of the present invention of specific setting timing
To this without setting.
Optionally, it also can choose idle period and terminal establish long connection, which refers to terminal in no net
In the idle period of network access or terminal is in its local idle period without carrying out various operations.When server and terminal are built
Vertical long connection, while when server issues assignment instructions to terminal, terminal receives the assignment instructions that server issues, and in the spare time
The task execution carried in assignment instructions is finished in period, without the Internet resources of the non-idle times of occupied terminal.
Illustratively, it is generally the case that terminal user may select to rest within the 12:00-13:00 period, claim the 12:00-13:
00 period was idle period, and the period in addition to 12:00-13:00 is referred to as non-idle times;Server can be selected in the sky
Idle section and terminal establish long connection, and issue to the terminal in idle period about system or application program updating, mend
Fourth reparation, the assignment instructions updated etc., terminal execute corresponding task.Above-mentioned idle period is in addition to including 12:00-13:00
It can also include 16:00-16:30 outside period, which is artificially arranged, and the specific embodiment of the present invention is to this
It is not limited.
Illustratively, timing and terminal can also be established long connection, selection idle period and terminal by the embodiment of the present invention
The two ways for establishing long connection is combined, i.e., other than server selection idle period and terminal establish long connection,
His non-idle times are in such a way that timing establishes long connection with terminal.For example, terminal starts to establish with server in 09:00
Network communication connection, the period that the timing of setting server establishes long connection with terminal is 30 minutes, when 12:00-13:00 is idle
Section;After first time determining terminal and the long connection of server foundation, server can check that its own whether there is and terminal is needed to hold
Capable assignment instructions, and if it exists, then connected based on the length to terminal and issue assignment instructions.According to the timing week pre-set
Phase establishes long connection with terminal, repeatedly, until the period of timing is in the idle period 12:00-13:00 set,
The idle period server and terminal establish long connection;Server can be since 13:00, according to preset timing week
Phase establishes long connection with terminal.The exemplary only citing of the setting of above-mentioned timing cycle and idle period, the embodiment of the present invention
This is not limited.
Mode two:
When current network transmission condition is better than pre- age threshold, long connection is established with terminal.
Pre- age threshold mentioned here is rule of thumb, is manually set, and the purpose that pre- age threshold is arranged is to prevent
Only in the case where the network transfer speeds of server and terminal are excessively slow, continues to establish server and the long of terminal connects, thus
Increase the load pressure of server or terminal.Wherein, it is 600K/s that pre- age threshold, which can be set, in the embodiment of the present invention, can also
Pre- age threshold is arranged as 400K/s.It is specific that it is not limited by the embodiments of the present invention.
Mode three:
When there is mission dispatching, long connection is established with terminal.
In the prior art, server can't issue assignment instructions to terminal in real time, server and end in the most of the time
The long connection that end is established is at idle state, occupies more network transmission resource.Network money is occupied in order to solve long connection
The problem of source, the embodiment of the present invention are used when there is mission dispatching, establish long connection with terminal.For example, carrying out the whole network killing
Virus or when the whole network vulnerability scanning, server can by mission dispatching to terminal, enable the terminal to timely killing virus or
Patching bugs.
Mode four:
The long connection of foundation according to the control of network management personnel, with terminal.
Under LAN environment, the network management personnel are to have permission the server or certain terminal that manage each terminal,
Wherein, above-mentioned to have permission that manage the server of each terminal be any one server in LAN environment;It is above-mentioned certain
Platform terminal can be controlled by operator, alternatively, can also be configured to the terminal, it is arranged with terminal and establishes long connection
Time or period, duration etc. are realized and automatically control.
It will be below certain terminal to the network management personnel, and the terminal as network management personnel can be controlled by operator
The case where processed, is described in detail, for example, server is first when server has the task of patch upgrading to need to be handed down to terminal
It is first communicated with the terminal as network management personnel, which can check terminal, and select
Terminal allows server and terminal to establish long connection in the period of less access network, wherein the terminal as network management personnel is selected
Terminal is selected in the period of less access network, needs to be selected according to the actual conditions of every terminal, the embodiment of the present invention
To selection terminal in the less specific period for accessing network without limiting.
Mode five:
The resource occupation information of itself is issued, to terminal so that long company is stated in the server foundation of terminal selection idle state
It connects.
In which, a communication server can be arranged in server end, which is used to count shared by terminal
Terminal, terminal are handed down to before server and terminal establish long connection with the information of each server resource, and by the information
The information issued according to communication server, the server for selecting and being in idle condition establish long connection.Illustratively, it is servicing
Device end, have a communication server, server 1, server 2, server 3 ... server end server absolutely not with
Resource occupation when terminal carries out network communication connection is 0, and the terminal of communication server statistics occupies the information of server resource
As follows: communication server is occupied by 5 terminals, resource occupation 15%, and server 1 is occupied by 20 terminals, and resource occupation is
60%, server 2 is occupied by 1 terminal, resource occupation 1%, and server 3 is occupied by 25 terminals, and resource occupation is
Information after statistics is sent to terminal by 62% ... the communication server, it is generally the case that in order to faster respond service
The task that device issues, terminal can select to establish long connection with the less server of resource occupation, above-mentioned Communications service phase statistics
In information, the percentage of resource occupation is bigger, indicates that server is busier.Wherein, above-mentioned communication server can be established with terminal
Long connection, while being used to the information of each server resource occupied by terminal;Alternatively, can also only be used to count occupied by terminal
The information of each server resource, without as the server for establishing long connection with terminal, the specific embodiment of the present invention pair
This is not limited.
Mode six:
The resource occupation information for obtaining terminal selects the terminal of idle state to establish long connection according to resource occupation information.
As also mentioned previously, the purpose that terminal and server establishes short connection is to keep the synchronism of data.It is protecting
Hold server it is synchronous with terminal data while server can obtain occupied information in terminal, resource occupation information in the terminal
Resource, the terminal operation external storage of the resource, terminal operation local application occupancy that occupy including terminal access network are set
The standby resource etc. occupied after server obtains the resource occupation information of terminal, selects the lesser terminal of resource occupation to establish length
Connection.
Illustratively, a server establishes network communication and connect with terminal 1, terminal 2, terminal 3, has in the server
When task needs to issue, terminal 1, terminal 2, the resource occupation information of terminal 3, the resource for the terminal which obtains first are obtained
Occupied information is as follows: terminal 1 accesses the resource that the resource that network occupies is 2%, terminal operation local application occupies and is
10%, the resource 30% that terminal operation External memory equipment occupies, it is that 50%, terminal is grasped that terminal 2, which accesses the resource that network occupies,
The resource for making local application occupancy is the resource 6% of 1%, terminal operation External memory equipment occupancy, and terminal 3 accesses network
The resource that the resource of occupancy is 1%, terminal operation local application occupies is 4%, terminal operation External memory equipment occupies
Resource 8%;The resource occupation information for every terminal that server will acquire carries out additional calculation, selects smaller with resource occupation
Terminal establish long connection.Wherein, resource occupation not only includes the resource of terminal access network occupancy, terminal in the terminal
Resource, the resource of terminal operation External memory equipment occupancy that local application occupies are operated, can also include different terminals
Between carry out Bluetooth wireless transmission etc., the specific embodiment of the present invention is not limited.
Above-mentioned example is to establish network communication with more terminals with a server to connect, and obtain the money of the more terminals
The explanation carried out for the occupied information of source is similarly established network communication with more terminals for multiple servers and is connect, and obtain
For the resource occupation information of corresponding more terminals, it can be every server and obtain respectively and establish network communication with its own
The resource occupation information of the terminal of connection, and the resource occupation information that will acquire carries out add operation, every server selection with
The corresponding lesser terminal of resource occupation establishes long connection, wherein the resource occupation of counterpart terminal is obtained about multiple servers
The description of information, please refers to above-mentioned related description, and the embodiment of the present invention is no longer repeated herein.
Mode seven:
The resource occupation state of itself is monitored, when resource occupation state reaches load threshold condition, to other
The long connection in server transfer part.
There can be a variety of situations when terminal and server establish long connection, for example, a server is built with more terminals
Vertical long connection a, alternatively, server and a terminal establish long connection etc..It establishes and grows with more terminals when a server
When connection, it is understood that there may be the server more terminals or since terminal is more than to the access of the server compared with slow-response
The load of the server causes the server not respond the more terminals etc..Therefore, in order to ensure server can be timely
The terminal of long connection is established in response therewith, and the mode that server detects the resource occupation state of its own works as server
In resource occupation state when reaching load threshold condition, can connect to other server transfer parts are long, can so drop
The load pressure of the low server reduces the expense of Internet resources, wherein the load threshold condition is rule of thumb, artificially
Setting.For example, server 1 and 5 terminal establishes long connection, server 2 and 1 terminal establishes long connection, server 3
Long connection is established with 0 terminal, server 4 and 2 terminal establishes long connection, and the load thresholding of resource occupation state is arranged
Condition is that every server can only at most establish long connection with 4 terminals, and above-mentioned server can resource occupation shape to its own
State is monitored, once reaching load threshold condition, what which can be intelligent connects to other server transfer parts are long, really
The terminal for continuing to establish long connection therewith can timely be responded by protecting the server.
Further, it as the refinement and extension to above-described embodiment, has been executed times executing above-mentioned steps 103 in terminal
After business, preset duration is waited, if not issuing new assignment instructions in waiting process, the length established with terminal is disconnected and connects,
In, which rule of thumb, is artificially arranged.Illustratively, it is 2 minutes that setting, which waits preset duration, terminal
After having executed the task that server issues, the long connection established with server will not be disconnected immediately, but in the waiting of setting
Server is checked in preset duration, and whether there is also newly issuing for tasks, if the time that terminal waits has been more than when waiting default
It is long, and server does not issue task also, then the long connection that disconnected end and server are established.It is designed in this way, prevents in terminal
After having executed a subtask, the long connection that disconnected end and server are established immediately, but server is there is also needs and at present
The task of hair.If within a short period of time, server issues the instruction information for establishing long connection to terminal again, terminal receives this and refers to
After showing information, long connection is established with the server, in this way, considerably increasing the expense of server network process resource.It increases
The load of server process resource.It is 2 minutes that the embodiment of the present invention, which can be set and wait preset duration, and it is pre- that waiting also can be set
If when it is 5 minutes a length of, the specific present invention implements to be not limited.
In implementation process, above-mentioned long connection can be TCP connection, or hypertext transfer protocol (HTTP-
Hypertext transfer protocol, HTTP) length connection.Specifically, it is not limited by the embodiments of the present invention.
It, can also be by it should be noted that terminal and server after establishing long connection, can be disconnected long connection by terminal
Server disconnects long connection.Specifically, the embodiment of the present invention is not limited.
Further, as an implementation of the above method, the embodiment of the present invention also provides a kind of dress for establishing long connection
It sets, as shown in Fig. 2, the device includes:
Unit 21 is established, for establishing long connection with terminal, terminal needs to send the request for establishing short connection to server
Information after server receives the solicited message, determines that establishing network communication with terminal connect.It establishes network communication and connects it
Afterwards, server is communicated with terminal, in communication process, when server discovery has data packet to need to be handed down to terminal, and clothes
Business device can send the instruction information for establishing long connection to terminal, receive the instruction for the long connection of foundation that server is sent in terminal
After information, terminal to server sends the solicited message for establishing long connection, establishes long connection with service;
Issuance unit 22 issues assignment instructions to terminal for the long connection by establishing the foundation of unit 21, so as to terminal
Corresponding task is executed according to assignment instructions, server can be connected to terminal by the length and issue assignment instructions, and terminal, which receives, appoints
After business instruction, which is parsed, obtains the task that simultaneously execute server issues;
Switching units 23, for disconnecting the length established with terminal after the task that terminal has executed that issuance unit 22 issues
Connection, after terminal has executed corresponding task according to assignment instructions, checks for being not carried out for task, is not carried out if it exists
Task, then continue to execute the task that server issues;Being not carried out if it does not exist for task then disconnects the length established with server
Connection.
Further, in the long connection procedure for keeping establishing the foundation of unit 21, the short connection established with terminal is disconnected, is
It is further to reduce the Internet resources for keeping long connection to occupy, after server and terminal establish long connection, disconnect in time with
The short connection that terminal is established.
Further, it in the long connection procedure for keeping establishing the foundation of unit 21, is connected when disconnecting with the long of terminal foundation
When, short connection is established with terminal, after the task that terminal has executed that server issues, disconnects the long connection established with server,
And the solicited message for establishing short connection is sent to server again, and after server receives the solicited message, determining and terminal
Establish network communication connection.
Further, it establishes unit 21 to be also used to, long connection is periodically established with terminal, timing mentioned here is built with terminal
Vertical long connection should establish network communication connection, and the basis for keeping terminal and server data synchronous in terminal and server
Upper realization.
Further, it establishes unit 21 to be also used to, idle period and terminal is selected to establish long connection, which refers to
Terminal is in the idle period that no network accesses or terminal is in its local idle period without carrying out various operations.Work as clothes
Device and the terminal of being engaged in establish long connection, while when server issues assignment instructions to terminal, terminal receives the task that server issues
Instruction, and finishes the task execution carried in assignment instructions in the idle section, without occupied terminal it is busy when
The Internet resources of section.
Further, it establishes unit 21 to be also used to, when current network transmission condition is better than pre- age threshold, with terminal
Long connection is established, pre- age threshold mentioned here is rule of thumb, is manually set, and the purpose that pre- age threshold is arranged is
It prevents in the case where the network transfer speeds of server and terminal are excessively slow, continues to establish server and the long of terminal connects, from
And increase the load pressure of server or terminal.
Further, it establishes unit 21 to be also used to when there is mission dispatching, establishes long connection with terminal, it is existing in order to solve
Server will not issue assignment instructions to terminal in real time in technology, and the long connection that server and terminal are established in the most of the time is all
The problem of being in idle state, occupying more network transmission resource, the embodiment of the present invention is used when there is mission dispatching, with end
Long connection is established at end.
Further, it establishes unit 21 to be also used to, according to the control of network management personnel, be connected with the foundation length of terminal, in office
Under the net environment of domain, the network management personnel are to have permission the server or certain terminal that manage each terminal, wherein above-mentioned to have the right
The server that limit manages each terminal can be any one server in LAN environment;Above-mentioned certain terminal can be by grasping
Make personnel control, alternatively, can also be configured to the terminal, be arranged its time that long connection is established with terminal or period,
Duration etc. is realized and is automatically controlled.
Further, it establishes unit 21 to be also used to, the resource occupation information of itself is issued to terminal, so that terminal selects sky
The server of not busy state establishes long connection, and a communication server can be arranged in server end, which is used to count eventually
The information of occupied each server resource is held, and the information is handed down to end before server and terminal establish long connection
End, the information that terminal is issued according to communication server, the server for selecting and being in idle condition establish long connection.
Further, unit 21 is established to be also used to:
The resource occupation information for obtaining terminal selects the terminal of idle state to establish long connection according to resource occupation information,
The purpose that terminal and server establishes short connection is to keep the synchronism of data.Keeping server synchronous with terminal data
Server can obtain occupied information in terminal simultaneously, and resource occupation information includes the money that terminal access network occupies in the terminal
The resource etc. that source, the resource of terminal operation local application occupancy, terminal operation External memory equipment occupy, server obtains
After taking the resource occupation information of terminal, the lesser terminal of resource occupation is selected to establish long connection.
Further, it establishes unit 21 to be also used to, the resource occupation state of itself is monitored;
When resource occupation state reaches load threshold condition, connected to other server transfer parts are long, terminal with
Server can have a variety of situations when establishing long connection, for example, a server establishes long connection with more terminals, alternatively, one
Platform server and a terminal establish long connection etc..When a server establishes long connection with more terminals, it is understood that there may be
The server more terminals or since terminal has been more than the load of the server to the access of the server compared with slow-response,
The server is caused not respond the more terminals etc..Therefore, in order to ensure server can timely respond to establish length therewith
The terminal of connection, the mode that server detects the resource occupation state of its own, when the resource occupation shape in server
When state reaches load threshold condition, it can be connected to other server transfer parts are long, can so reduce the negative of the server
Lotus pressure reduces the expense of Internet resources, wherein the load threshold condition is rule of thumb, is manually set.
Further, switching units 23 are also used to:
After terminal has executed task, preset duration is waited to disconnect if not issuing new assignment instructions in waiting process
The long connection established with terminal, wherein the waiting preset duration rule of thumb, is artificially arranged.Illustratively, setting waits
Preset duration is 2 minutes, and terminal will not disconnect the long company established with server after having executed the task that server issues immediately
Connect, but checked in the waiting preset duration of setting server whether there is also newly issuing for task, if terminal wait when
Between be more than waiting preset duration, and server does not issue task also, then what disconnected end and server were established long connects.
Further, length is connected as TCP connection.
Further, as an implementation of the above method and the application of above-mentioned apparatus, the embodiment of the present invention also provide one
The system that kind establishes long connection, as shown in figure 3, the system includes: terminal 31 and server 32, wherein server 32 includes upper
State Fig. 2 shown device.
The long connection that the apparatus and system provided in an embodiment of the present invention for establishing connection is established based on server and terminal, clothes
Business device is connected to terminal by the length and issues assignment instructions, and terminal receives the assignment instructions and goes execution pair according to the assignment instructions
Answering for task disconnects the long connection established with server after having executed task.Compared with prior art, in the present invention, terminal can
To establish the best opportunity of long connection with server according to the demand of itself selection, and server can also have been executed in terminal
After issuing for task, the long connection established with server is interrupted, this kind of mode reduces server and terminal is always maintained at long company
The Internet resources occupied when connecing.
In the above-described embodiments, it all emphasizes particularly on different fields to the description of each embodiment, there is no the portion being described in detail in some embodiment
Point, reference can be made to the related descriptions of other embodiments.
It is understood that the correlated characteristic in the above method and device can be referred to mutually.In addition, in above-described embodiment
" first ", " second " etc. be and not represent the superiority and inferiority of each embodiment for distinguishing each embodiment.
It is apparent to those skilled in the art that for convenience and simplicity of description, the system of foregoing description,
The specific work process of device and unit, can refer to corresponding processes in the foregoing method embodiment, and details are not described herein.
Algorithm and display are not inherently related to any particular computer, virtual system, or other device provided herein.
Various general-purpose systems can also be used together with teachings based herein.As described above, it constructs required by this kind of system
Structure be obvious.In addition, the present invention is also not directed to any particular programming language.It should be understood that can use various
Programming language realizes summary of the invention described herein, and the description done above to language-specific is to disclose this hair
Bright preferred forms.
In the instructions provided here, numerous specific details are set forth.It is to be appreciated, however, that implementation of the invention
Example can be practiced without these specific details.In some instances, well known method, structure is not been shown in detail
And technology, so as not to obscure the understanding of this specification.
Similarly, it should be understood that in order to simplify the disclosure and help to understand one or more of the various inventive aspects,
Above in the description of exemplary embodiment of the present invention, each feature of the invention is grouped together into single implementation sometimes
In example, figure or descriptions thereof.However, the disclosed method should not be interpreted as reflecting the following intention: i.e. required to protect
Shield the present invention claims features more more than feature expressly recited in each claim.More precisely, as following
Claims reflect as, inventive aspect is all features less than single embodiment disclosed above.Therefore,
Thus the claims for following specific embodiment are expressly incorporated in the specific embodiment, wherein each claim itself
All as a separate embodiment of the present invention.
Those skilled in the art will understand that can be carried out adaptively to the module in the equipment in embodiment
Change and they are arranged in one or more devices different from this embodiment.It can be the module or list in embodiment
Member or component are combined into a module or unit or component, and furthermore they can be divided into multiple submodule or subelement or
Sub-component.Other than such feature and/or at least some of process or unit exclude each other, it can use any
Combination is to all features disclosed in this specification (including adjoint claim, abstract and attached drawing) and so disclosed
All process or units of what method or apparatus are combined.Unless expressly stated otherwise, this specification is (including adjoint power
Benefit require, abstract and attached drawing) disclosed in each feature can carry out generation with an alternative feature that provides the same, equivalent, or similar purpose
It replaces.
In addition, it will be appreciated by those of skill in the art that although some embodiments described herein include other embodiments
In included certain features rather than other feature, but the combination of the feature of different embodiments mean it is of the invention
Within the scope of and form different embodiments.For example, in the following claims, embodiment claimed is appointed
Meaning one of can in any combination mode come using.
Various component embodiments of the invention can be implemented in hardware, or to run on one or more processors
Software module realize, or be implemented in a combination thereof.It will be understood by those of skill in the art that can be used in practice
Microprocessor or digital signal processor (DSP) are some or complete in denomination of invention according to an embodiment of the present invention to realize
The some or all functions of portion's component.The present invention be also implemented as a part for executing method as described herein or
The device or device program (for example, computer program and computer program product) of person's whole.Such realization is of the invention
Program can store on a computer-readable medium, or may be in the form of one or more signals.Such signal
It can be downloaded from an internet website to obtain, be perhaps provided on the carrier signal or be provided in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and ability
Field technique personnel can be designed alternative embodiment without departing from the scope of the appended claims.In the claims,
Any reference symbol between parentheses should not be configured to limitations on claims.Word "comprising" does not exclude the presence of not
Element or step listed in the claims.Word "a" or "an" located in front of the element does not exclude the presence of multiple such
Element.The present invention can be by means of including the hardware of several different elements and being come by means of properly programmed computer real
It is existing.In the unit claims listing several devices, several in these devices can be through the same hardware branch
To embody.The use of word first, second, and third does not indicate any sequence.These words can be explained and be run after fame
Claim.