Invention content
In view of this, the embodiment of the present invention provides a kind of method, apparatus and system for establishing connection, it being capable of settlement server
Mission dispatching not in time the problem of.
According to the present invention on one side, a kind of method for establishing connection is provided, including:
It is established with server and keeps long connection;
Include task notifications message in assignment instructions based on the long assignment instructions for connecting and receiving server and issuing;
Task notifications message is parsed, the attribute information of task is obtained;
Short connection is established with server, and attribute information is reported based on short connect to server, to obtain under server
The task of hair.
According to another aspect of the present invention, a kind of device for establishing connection is provided, including:
First establishing unit, for being established with server and keeping long connection;
Receiving unit, the long connection for being established and being kept based on first establishing unit are received the task that server issues and referred to
It enables, includes task notifications message in assignment instructions;
Resolution unit, the task notifications message for being received to receiving unit parse, and obtain the attribute information of task;
Second establishes unit, for after the attribute information that resolution unit obtains task, short connection to be established with server;
Reporting unit, the short connection for establishing unit foundation based on second report the category that resolution unit obtains to server
Property information, to obtain the task that server issues.
According to another aspect of the present invention, a kind of system for establishing connection is provided, including:
Terminal and server, wherein terminal includes device as described above;
Server is used for:
It is established with terminal and keeps long connection;
Assignment instructions are issued to terminal based on long connection, include task notifications message in assignment instructions;
Short connection is established with terminal, the attribute information that terminal reports is received based on short connection, is searched and is appointed according to attribute information
It is engaged in and is handed down to terminal;
Wherein, attribute information is that terminal is obtained by parsing task notifications message.
By above-mentioned technical proposal, the method, apparatus and system provided by the invention for establishing connection can be in terminal and clothes
It is established on the basis of short connection between business device, long connection is further established and keep, when server needs to issue task to terminal
When, assignment instructions can be handed down to terminal by the long connection of holding, after receiving the assignment instructions that server issues, eventually
End can establish short connection with server, and be believed the attribute for parsing the task that the assignment instructions obtain by the short connection of foundation
Breath is reported to server, and server searches task according to the attribute information and is handed down to terminal.In the present invention, due to terminal and clothes
Long connection is always maintained between business device, therefore, server to various tasks can actively issue at any time, with the prior art
Compare, the present invention can in time, active by various mission dispatchings to terminal, there is no mission dispatchings to postpone.
Above description is only the general introduction of technical solution of the present invention, in order to better understand the technical means of the present invention,
And 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, below the special specific implementation mode for lifting the present invention.
Specific implementation mode
The exemplary embodiment of the disclosure is more fully described 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
Completely it is communicated to those skilled in the art.
An embodiment of the present invention provides a kind of methods for establishing connection, as shown in Figure 1, this method includes:
101, it establishes with server and keeps long connection.
When terminal and server, which are established, to be connected, terminal establishes long connection with server, and terminal needs to send to server
The request bag of connection, waiting for server confirm;When server receives the request bag of terminal transmission and confirms the request data package
Afterwards, the data packet of the request data package and server itself is sent to terminal;When terminal receives the data of server transmission
The data packet that simultaneously confirmed service device is sent is wrapped, while being sent to server and confirming data packet, thus terminal and server is just completed
Long establishment of connection., can be continuously to opposite end transmission data packet after terminal and server establishes long connection, and terminal kimonos
Business device can be always maintained at long connection.Long connection is established and keeps by using terminal and server, so that server can be timely
Data packet is actively issued to terminal.
102, the assignment instructions that server issues are received based on long connection, includes task notifications message in assignment instructions.
Assignment instructions in this step are generated by server, and are handed down to terminal in time, and terminal is according in the assignment instructions
Notification message respond the assignment instructions.When server issues assignment instructions to terminal, pass through terminal in step 101 and service
The long connection that device is established issues assignment instructions to terminal in time, includes task notifications message in the assignment instructions, passes through the task
Notification message informs this task definition of terminal.If server to terminal issue assignment instructions be it is multiple when, elder generation may be used
Send one of assignment instructions to terminal, etc. after terminals have responded the assignment instructions, issue other tasks to terminal again
Instruction;Or it is all sent to terminal using by the multiple tasks instruction of server end, terminal selects first according to the demand of itself
Which assignment instructions first responded.Specifically the mode embodiment of the present invention of assignment instructions is issued to terminal to this not about server
It is limited.
Wherein, about the task notifications message embodiment of the present invention can including but not limited to the following contents, for example, this
Business notification message is patch reparation, or system or application program updating etc., the specific embodiment of the present invention is to this
It is not limited.
103, task notifications message is parsed, obtains the attribute information of task.
The task notifications message that server issues in terminal receiving step 102 has recorded service in the task notifications message
Device issues the attribute information of assignment instructions, and terminal needs, by parsing the task notifications message, to obtain the category of the task
Property information.Wherein the attribute information includes at least:Identity ID, order, time, packet length, type, check bit word etc., tool
The embodiment of the present invention of body is not limited.
Wherein, it may include when parsing task notifications message but be not limited to mode below and realize:It is logical to the task
Know that the content in message is parsed one by one, obtains the attribute information of all tasks;Alternatively, only parsing executes the task notifications
Content necessary to message executes the content that the task notifications message must obtain for example, rule of thumb searching, will find
Content field parsed, and the attribute information of the task definition field is obtained, wherein the above-mentioned execution task notifications message
Necessary content, the terminal and server by establishing connection consult to decide;Alternatively, traversing the task notifications message, selector
Divide and executes the part attribute information etc. that the content that the task notifications message must obtain is parsed, and obtains the task.
About the resolving to task notifications message, it is not limited by the embodiments of the present invention.
104, short connection is established with server, and attribute information is reported based on short connect to server, to be serviced
The task that device issues.
Terminal establishes the process of short connection with server, please refers to terminal and server in above-mentioned steps 101 and establishes long connect
The process connect specifically establishes the process embodiment of the present invention of short connection to this without repeating, eventually about terminal and server
End and server establish short connection, and server, after responding terminal request, terminal or server can interrupt this time eventually
The connection at end and server.
After the attribute information of the task of acquisition, terminal and server establishes short connection, due to the terminal in a step 101 with
Server is established and keeps long connection, in this step, in order to reduce the occupancy of Internet resources, while times that server issues
Business instruction is disposable effective under normal conditions, and terminal establishes short connection with server;It short is connected on server based on this
The attribute information that parses in report step 103, server is searched according to the attribute information and issues task to terminal, thus complete
At a server task is issued to terminal in time.
The method provided by the invention for establishing connection, on the basis of short connection can be established between terminal and server,
Long connection is further established and kept, when server needs to issue task to terminal, can will be appointed by the long connection of holding
Business instruction is handed down to terminal, and after receiving the assignment instructions that server issues, terminal can establish short connection with server, and
The attribute information for parsing the task that the assignment instructions obtain is reported to server by the short connection of foundation, server is according to this
Attribute information searches task and is handed down to terminal.It is long due to being always maintained between terminal and server in the embodiment of the present invention
Connection, therefore, server to various tasks can actively issue at any time, compared with prior art, energy of the embodiment of the present invention
It is enough in time, active by various mission dispatchings to terminal, there is no mission dispatchings to postpone.
Further, in another embodiment of the invention, it is established with server in execution above-mentioned steps 101 and keeps long
When connection, following manner can also be used:Terminal first passage is short connect to server request data when, terminal and server
The connection of this terminal and server will not be interrupted, but after the request data that server responds terminal, terminal is again to this
Server sends the request for establishing long connection, is established with server and keeps long connection.
Further, in assignment instructions include task in above-mentioned steps 102 as the refinement and extension to above-described embodiment
Notification message can be presented in the form of formatting message, and terminal disappears according to the content formatted in message, parsing task notifications
Breath, to obtain the attribute information of task.
In implementation process, message is formatted in addition to content field, can also include:Identity id field, command word
Section, time field, the long field of packet, type field, verification bit field;Wherein, different tasks corresponds to different identity ID
By server sets itself, for example, when server issues first task of patch reparation, this can be arranged in field, id field
Id field is XF001, and when server issues second task of patch reparation, it is XF002 that the id field, which can be arranged, works as service
When device issues first task of upgrading, it is SJ001 that the id field, which can be arranged, when server issues second task of upgrading
When, it is SJ002 etc., the exemplary only citing of set-up mode of above-mentioned id field, this specific hair that the id field, which can be arranged,
Bright embodiment is not limited this.
Illustratively, command field is that server-side instruction terminal needs the order executed, for example, unloading, upgrading, patch are repaiied
It is multiple etc.;Time field may include but be not limited to have recorded server in content below, such as time field and issue to appoint
Be engaged in instruction the time either assignment instructions generated time can also be server requirement terminal which time or when
Between time of the assignment instructions is executed in section, the specific embodiment of the present invention is not limited;Wrap the long field record task
The size of instruction, for example, wrapping a length of 10K, 8K etc., the embodiment of the present invention does not limit the size of the assignment instructions specifically
It is fixed;Type field is for which type of operation, for example, upgrading, patch reparation, update unloading etc., in practical operation
It is set according to actual conditions, the specific embodiment of the present invention is to this without limiting;It is according to content word to verify bit field
What section, identity id field, command field, time field, the long field of packet, type field etc. were calculated, according to above-mentioned
The difference of field and it is different.
Optionally, the embodiment of the present invention is when terminal and server establish long connection, using the TCP long based on proprietary protocol
Connection, this kind of connection type do not have special unified standard, and easy to maintain;Certainly, it can also use and be based in practical application
The TCP long connections of publicly-owned agreement, it is not limited by the embodiments of the present invention for specific long connection type.
Optionally, when terminal and server carry out establishing short connection, it may be employed without limitation of mode below real
It is existing, it is connected for example, terminal is established with server by the short connections of HTTP, terminal and service can also be established by the short connections of TCP
Connection between device.The embodiment of the present invention is not limited the type of specific short connection.
Above-mentioned example is the explanation carried out so that terminal and server establishes a long connection as an example, and similarly, one is taken
Business device is established with more station terminals and is protected for long connection, and the identity mark in message can will be formatted when issuing task to terminal
Know id field to be configured according to different terminals, for example, when a server is established with terminal 1, terminal 2, terminal 3 ...
And long connection is kept, when issuing assignment instructions to above-mentioned terminal, it may be used such as under type:When server issues benefit to terminal 1
When first task of fourth reparation, it is 001XF001 that the id field, which can be arranged, when server issues the of patch reparation to terminal 2
When one task, it is 002XF001 that the id field, which can be arranged, when server issues to terminal 3 first task of patch reparation
When, it is 003XF001 that the id field, which can be arranged,;When server issues second task of patch reparation to terminal 1, can be arranged
The id field is 001XF002, and when server issues second task of patch reparation to terminal 2, the id field, which can be arranged, is
002XF002, when server issues second task of patch reparation to terminal 3, it is 003XF002 that the id field, which can be arranged,;
When server issues first task of upgrading to terminal 1, it is 001SJ001 that the id field, which can be arranged, when server is to terminal
2 when issuing first task of upgrading, and it is 002SJ001 that the id field, which can be arranged, when server issues the of upgrading to terminal 3
When one task, it is 003SJ001 that the id field, which can be arranged,;It, can when server issues second task of upgrading to terminal 1
It is 001SJ002 that the id field, which is arranged, and when server issues second task of upgrading to terminal 2, the id field, which can be arranged, is
002SJ002, when server issues second task of upgrading to terminal 3, it is 003SJ002 etc. that the id field, which can be arranged,.
The exemplary only citing of set-up mode of above-mentioned id field, specific it is not limited by the embodiments of the present invention.
One server issues assignment instructions to more station terminals, receives more station terminals of the assignment instructions to the assignment instructions
It is parsed, wherein the parsing for the assignment instructions that related end-on receives and establish short connection with server, and based on short
The process for reporting attribute information to server is connected, above-mentioned steps 103, the specific descriptions with step 104 are please referred to, the present invention is real
Example is applied to this without repeating.
Based on above method embodiment, the embodiment of the present invention also provides a kind of device for establishing connection, as shown in Fig. 2, should
Device includes:
First establishing unit 21, for long connection to be established and kept with server, when terminal and server foundation connection,
Terminal establishes long connection with server, and terminal needs to send the request bag of connection to server, and waiting for server confirms;Work as service
After device receives the request bag of terminal transmission and confirms the request data package, by the data of the request data package and server itself
Packet is sent to terminal;When the data packet that terminal receives the data packet of server transmission and confirmed service device is sent, while to clothes
Business device, which is sent, confirms data packet, and thus terminal and server just completes long establishment of connection.Terminal and server establishes long connect
, can be continuously to opposite end transmission data packet after connecing, and terminal and server can be always maintained at long connection.By using terminal with
Long connection is established and kept to server, so that server actively can issue data packet to terminal in time;
Receiving unit 22, the long connection for being established and being kept based on first establishing unit 21 receive times that server issues
Business instructs, and includes task notifications message in assignment instructions, which is generated by server, and is handed down to terminal in time, eventually
End responds the assignment instructions according to the notification message in the assignment instructions.When server issues assignment instructions to terminal, pass through
Terminal issues assignment instructions to terminal in time with the long connection that server is established, and includes task notifications message in the assignment instructions,
This task definition of terminal is informed by the task notifications message;
Resolution unit 23, the task notifications message for being received to receiving unit 22 parse, and obtain the attribute of task
Information, terminal receive the task notifications message that issues of server, have recorded server in the task notifications message and issue task and refer to
The attribute information of order, terminal need, by parsing the task notifications message, to obtain the attribute information of the task.Wherein should
Attribute information includes at least:Identity ID, order, time, packet length, type, check bit word etc., the specific present invention is implemented
Example is not limited;
Second establishes unit 24, for after the attribute information that resolution unit 23 obtains task, short company to be established with server
It connects, after the attribute information of the task of acquisition, terminal and server establishes short connection, due to the terminal in first establishing unit 21
Long connection is established and kept with server, and in order to reduce the occupancy of Internet resources, while the assignment instructions that server issues are logical
It is disposable effective in the case of often, terminal establishes short connection with server;
Reporting unit 25, the short connection for establishing the foundation of unit 24 based on second report resolution unit 23 to obtain to server
Attribute information establish the short connection of the foundation of unit 24 to server based on second to obtain the task that server issues
Resolution unit 23 is reported to parse obtained attribute information, server is searched according to the attribute information and issues task to terminal, by
This completes a server and issues task to terminal in time.
Further, the first establishing unit 21 be used for first passage is short connect to server request data when, establish
And keep long connection.
Further, the task notifications message for including in the assignment instructions which receives is to format message.
Further, the resolution unit 23 obtains the ground of task for being read out to the content field for formatting message
Location information.
Further, the formatting message which receives further includes following field:Identity id field, life
Enable field, time field, the long field of packet, type field, verification bit field.
Further, which establishes and the length kept is connected as transmission control protocol TCP length connection, should
Second, which establishes the short of the foundation of unit 24, is connected as the short connections of hypertext transfer protocol HTTP.
Further, the embodiment of the present invention also provides a kind of system for establishing connection, as shown in figure 3, the system includes:Eventually
End 31 and server 32, wherein the terminal 31 is device as shown in Figure 2 above;
Server 32, is used for:
It is established with terminal 31 and keeps long connection;
Assignment instructions are issued to terminal 31 based on long connection, include task notifications message in assignment instructions;
Short connection is established with terminal 31, the attribute information that terminal 31 reports is received based on short connection, is looked into according to attribute information
It looks for task and is handed down to terminal 31;
Wherein, attribute information is that terminal 31 is obtained by parsing task notifications message.
The apparatus and system provided by the invention for establishing connection, can establish the base of short connection between terminal and server
On plinth, long connection is further established and kept, when server needs to issue task to terminal, can be connected by the long of holding
Assignment instructions are handed down to terminal, after receiving the assignment instructions that server issues, terminal can establish short company with server
It connects, and the attribute information for parsing the task that the assignment instructions obtain is reported to by server, server by the short connection of foundation
Task is searched according to the attribute information and is handed down to terminal.In the embodiment of the present invention, due to being protected always between terminal and server
Long connection is hold, therefore, server to various tasks can actively issue at any time, and compared with prior art, the present invention is real
Apply example can in time, active by various mission dispatchings to terminal, there is no mission dispatchings to postpone.
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, it may refer to the associated description of other embodiment.
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 quality 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 be not inherently related to any certain computer, virtual system or miscellaneous equipment provided herein.
Various general-purpose systems can also be used together with teaching based on this.As described above, it constructs required by this kind of system
Structure be obvious.In addition, the present invention is not also directed to any certain programmed language.It should be understood that can utilize various
Programming language realizes the content of 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 the implementation of the present invention
Example can be put into practice 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 description.
Similarly, it should be understood that in order to simplify the disclosure and help to understand one or more of each inventive aspect,
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 method for the disclosure should be construed to reflect following intention:It is i.e. required to protect
Shield the present invention claims the more features of feature than being 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 implementation mode are expressly incorporated in the specific implementation mode, wherein each claim itself
All as a separate embodiment of the present invention.
Those skilled in the art, which are appreciated that, to carry out adaptively the module in the equipment in embodiment
Change and they are arranged in the one or more equipment different from the embodiment.It can be the module or list in embodiment
Member or component be combined into a module or unit or component, and can be divided into addition multiple submodule or subelement or
Sub-component.Other than such feature and/or at least some of process or unit exclude each other, it may be used any
Combination is disclosed to all features disclosed in this specification (including adjoint claim, abstract and attached drawing) and so to appoint
Where all processes or unit of method or equipment are combined.Unless expressly stated otherwise, this specification (including adjoint power
Profit requires, abstract and attached drawing) disclosed in each feature can be by providing the alternative features of identical, equivalent or similar purpose come generation
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 means in of the invention
Within the scope of and form different embodiments.For example, in the following claims, embodiment claimed is appointed
One of meaning mode can use in any combination.
The all parts embodiment of the present invention can be with hardware realization, or to run on one or more processors
Software module realize, or realized with combination thereof.It will be understood by those of skill in the art that can use in practice
Microprocessor or digital signal processor (DSP) come realize the method, apparatus according to the ... of the embodiment of the present invention for establishing connection and
The some or all functions of some or all components in system.The present invention is also implemented as being retouched here for executing
The some or all equipment or program of device (for example, computer program and computer program product) for the method stated.
It is such to realize that the program of the present invention may be stored on the computer-readable medium, or can have one or more signal
Form.Such signal can be downloaded from internet website and be obtained, either provide on carrier signal or with it is any its
He provides form.
It should be noted that the present invention will be described rather than limits the invention for above-described embodiment, and ability
Field technique personnel can design alternative embodiment without departing from the scope of the appended claims.In the claims,
Any reference mark between bracket 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" before 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 by the same hardware branch
To embody.The use of word first, second, and third does not indicate that any sequence.These words can be explained and be run after fame
Claim.