Summary of the invention
The technical problem to be solved in the present invention is to provide a kind of to connecting the method and system of carrying out two-way detection, improves test performance.
In order to solve the problems of the technologies described above, the invention provides a kind of connection-oriented link bidirectional detection method, comprising: service end and client are carried out respectively heartbeat detection to connection between the two; In the heartbeat detection flow process of initiating in client, described client and described service end identify by sending order the heartbeat detection flow process message of sending, and described client judges according to the sign in the heartbeat detection response receiving whether this heartbeat detection response is the response for the last heartbeat detection request sending of this client.
Further, said method can also have following characteristics:
The heartbeat detection flow process of initiating for client, described client maintenance request serial number also identifies this request serial number in the heartbeat detection request of sending, and described service end is safeguarded response sequence number and identify this response sequence number in the heartbeat detection response of sending; During initialization, request serial number is less than or equal to response sequence number; Described service end is received after heartbeat detection request, judge when in this request, request serial number is less than or equal to it and safeguards response sequence, response sequence number is increased to predetermined interval value, in the heartbeat detection response of returning to described client, identify the response sequence number after this renewal; Described client is received after heartbeat detection response in default heartbeat detection timing, judge when in this response, response sequence number is greater than the request serial number of its maintenance, request serial number is upgraded to the value of response sequence for this reason number, and the request serial number after identifying this in the heartbeat detection request sending in next heartbeat detection cycle and upgrading.
Further, said method can also have following characteristics:
Described client is received after heartbeat detection response in default heartbeat detection timing, judge when in this response, response sequence number is less than or equal to the request serial number of its maintenance, maintain the value of request serial number, and identify this request serial number in the heartbeat detection request of next heartbeat detection cycle transmission.
Further, said method can also have following characteristics:
Described service end or described client are in carrying out heartbeat detection process, to opposite equip., send after heartbeat detection request, while not receiving the heartbeat detection response of opposite end in the default heartbeat detection timing of local terminal, reduce the duration that the request of local terminal heartbeat detection sends the cycle.
Further, said method can also have following characteristics:
The heartbeat detection flow process of initiating for service end, described service end is sent heartbeat detection request and identify generic sequence number in this request to client, client is received after described heartbeat detection request, the sign sequence number value identical with sequence number in described heartbeat detection request in the heartbeat detection response of returning, described service end is received after heartbeat detection response in default heartbeat detection timing, described sequence number is increased to predetermined interval value, and identify the sequence number after this renewal in the heartbeat detection request of next heartbeat detection cycle transmission.
In order to solve the problems of the technologies described above, it is a kind of to connecting the system of carrying out two-way detection that the present invention also provides, and comprises service end and the client of opposite end being carried out to heartbeat detection; Described service end, the heartbeat detection flow process for initiating in client, identifies by sending order the heartbeat detection response message sending; Described client, for the heartbeat detection flow process of initiating in client, the heartbeat detection request message sending is identified by sending order, and judge according to the sign in the heartbeat detection response receiving whether this heartbeat detection response is the response for the last heartbeat detection request sending of this client.
Further, said system can also have following characteristics:
Described service end, the heartbeat detection flow process for initiating for client also, safeguards response sequence number and identify this response sequence number in the heartbeat detection response of sending; After receiving heartbeat detection request, judge when in this request, request serial number is less than or equal to it and safeguards response sequence, response sequence number is increased to predetermined interval value, the response sequence number after identifying this upgrade in the heartbeat detection response of returning to described client; Described client, also, for the heartbeat detection flow process for client initiation, maintenance request sequence number also identifies this request serial number in the heartbeat detection request of sending; The response sequence number that the request serial number arranging when initialization arranges while being greater than described service end initialization; In default heartbeat detection timing, receive after heartbeat detection response, judge when in this response, response sequence number is greater than the request serial number of its maintenance, request serial number is upgraded to the value of response sequence for this reason number, and the request serial number after identifying this in the heartbeat detection request sending in next heartbeat detection cycle and upgrading.
Further, said system can also have following characteristics:
Described client, also for receiving in the heartbeat detection timing default after heartbeat detection response, judge when in this response, response sequence number is less than or equal to the request serial number of its maintenance, maintain the value of request serial number, and identify this request serial number in the heartbeat detection request of next heartbeat detection cycle transmission.
Further, said system can also have following characteristics:
Described service end or described client, also for carrying out heartbeat detection process, to opposite equip., send after heartbeat detection request, while not receiving the heartbeat detection response of opposite end in the default heartbeat detection timing of local terminal, reduce the duration that the request of local terminal heartbeat detection sends the cycle.
Further, said system can also have following characteristics:
Described service end, also the heartbeat detection flow process for initiating in service end, sends heartbeat detection request and identify generic sequence number in this request to client; In default heartbeat detection timing, receive after heartbeat detection response, described sequence number is increased to predetermined interval value, and identify the sequence number after this renewal in the heartbeat detection request of next heartbeat detection cycle transmission;
Described client, also, for the heartbeat detection flow process initiating in service end, receives after heartbeat detection request, the sign sequence number value identical with sequence number in described heartbeat detection request in the heartbeat detection response of returning.
The present invention can improve the test performance to connecting, and whether record in time connection normal.
Embodiment
The system of carrying out two-way detection to connecting comprises service end and the client of opposite end being carried out to heartbeat detection.
Service end, for the heartbeat detection flow process initiating in client, identifies by sending order the heartbeat detection response message sending.
The heartbeat detection flow process of client for initiating in client, identifies by sending order the heartbeat detection request message sending; And judge according to the sign in the heartbeat detection response receiving whether this heartbeat detection response is the response for the last heartbeat detection request sending of this client.
Concrete, in the heartbeat detection flow process of initiating in client, system guarantees the accuracy of test in the following manner:
The heartbeat detection flow process of service end for initiating for client, safeguards response sequence number and identify this response sequence number in the heartbeat detection response of sending; Receive after heartbeat detection request, judge when request serial number is less than or equal to it and safeguards response sequence in this request, response sequence number is increased to predetermined interval value, the response sequence number after identifying this upgrade in the heartbeat detection response of returning to client.
The heartbeat detection flow process of client for initiating for client, maintenance request sequence number also identifies this request serial number in the heartbeat detection request of sending; The response sequence number that the request serial number arranging when initialization arranges while being greater than service end initialization; In default heartbeat detection timing, receive after heartbeat detection response, judge when in this response, response sequence number is greater than the request serial number of its maintenance, request serial number is upgraded to the value of response sequence for this reason number, and the request serial number after identifying this in the heartbeat detection request sending in next heartbeat detection cycle and upgrading.
Client is also for receiving in the heartbeat detection timing default after heartbeat detection response, judge when in this response, response sequence number is less than or equal to the request serial number of its maintenance, maintain the value of request serial number, and identify this request serial number in the heartbeat detection request of next heartbeat detection cycle transmission.
Native system capable of dynamic is adjusted the number of times of the frequency that in heartbeat detection, request sends, and while making network state abnormal, initiates faster heartbeat detection next time, knows in time the normal state of network recovery.
Service end, for carrying out heartbeat detection process, is sent after heartbeat detection request to opposite equip., while not receiving the heartbeat detection response of opposite end in the default heartbeat detection timing of local terminal, reduces the duration that the request of local terminal heartbeat detection sends the cycle.
Client, for carrying out heartbeat detection process, is sent after heartbeat detection request to opposite equip., while not receiving the heartbeat detection response of opposite end in the default heartbeat detection timing of local terminal, reduces the duration that the request of local terminal heartbeat detection sends the cycle.
The heartbeat detection that the heartbeat detection that native system is initiated for client and service end are initiated adopts validity determining program in various degree, the heartbeat detection of initiating for client, adopt the comparatively strict detection mode of above-mentioned application request sequence number and response sequence number, accuracy is higher, the heartbeat detection of initiating for service end, adopt the comparatively simple examination that detects, computation rate is very fast.
In the heartbeat detection flow process of initiating in service end, realize in the following ways:
The heartbeat detection flow process of service end for initiating in service end, sends heartbeat detection request and identify generic sequence number in this request to client; In default heartbeat detection timing, receive after heartbeat detection response, sequence number is increased to predetermined interval value, and identify the sequence number after this renewal in the heartbeat detection request of next heartbeat detection cycle transmission.
Client, for the heartbeat detection flow process initiating in service end, is received after heartbeat detection request, the sign sequence number value identical with sequence number in heartbeat detection request in the heartbeat detection response of returning.
In native system, service end or client are when repeating transmission heartbeat detection request number of times reaches default maximum retransmission and all do not receive heartbeat detection response in default heartbeat detection timing, and judgement connects extremely, nullifies and connects corresponding user.
The service end of native system comprises be responsible for to be set up and safeguards the link block that is connected and for carrying out the heartbeat detection module of above-mentioned heartbeat detection, link block comprises that authentication submodule and user safeguard submodule.Authentication submodule is for authenticating user, and authentication by after notify user to safeguard submodule, user safeguards that the user that submodule passes through authentication is updated to data field.Heartbeat detection module is when repeating transmission heartbeat detection request number of times reaches default maximum retransmission and all do not receive heartbeat detection response in default heartbeat detection timing, judgement connects abnormal, and safeguarding submodule report of user logout message to user, user safeguards that submodule deletes user.
The service end of native system comprises be responsible for to be set up and safeguards the link block that is connected and for carrying out the heartbeat detection module of above-mentioned heartbeat detection.Link block for to service end, initiate that user authenticates and after authentication success for user creates user data area.Heartbeat detection module is when repeating transmission heartbeat detection request number of times reaches default maximum retransmission and all do not receive heartbeat detection response in default heartbeat detection timing, judgement connects abnormal, and reporting disconnecting message to this link block, this link block is deleted user.
As shown in Figure 1, connection-oriented link bidirectional detection method comprises: service end and client are carried out respectively heartbeat detection to connection between the two; In the heartbeat detection flow process of initiating in client, client and service end identify by sending order the heartbeat detection flow process message of sending, and client judges according to the sign in the heartbeat detection response receiving whether this heartbeat detection response is the response for the last heartbeat detection request sending of this client.
In the heartbeat detection flow process of initiating in client, guarantee in the following manner the accuracy of test:
The heartbeat detection flow process of initiating for client, client maintenance request serial number also identifies this request serial number in the heartbeat detection request of sending, and service end is safeguarded response sequence number and identify this response sequence number in the heartbeat detection response of sending; During initialization, request serial number is less than or equal to response sequence number.
Service end receives after heartbeat detection request, judges in this request when request serial number is less than or equal to it and safeguards response sequence, and response sequence number is increased to predetermined interval value, the response sequence number after identifying this upgrade in the heartbeat detection response of returning to client.
Client is received after heartbeat detection response in default heartbeat detection timing, judge when in this response, response sequence number is greater than the request serial number of its maintenance, request serial number is upgraded to the value of response sequence for this reason number, and the request serial number after identifying this in the heartbeat detection request sending in next heartbeat detection cycle and upgrading.
Client is received after heartbeat detection response in default heartbeat detection timing, judge when in this response, response sequence number is less than or equal to the request serial number of its maintenance, maintain the value of request serial number, and identify this request serial number in the heartbeat detection request of next heartbeat detection cycle transmission.
The heartbeat detection that the heartbeat detection that native system is initiated for client and service end are initiated adopts validity determining program in various degree, the heartbeat detection of initiating for client, adopt the comparatively strict detection mode of above-mentioned application request sequence number and response sequence number, accuracy is higher, the heartbeat detection of initiating for service end, adopt the comparatively simple examination that detects, computation rate is very fast.
In the heartbeat detection flow process of initiating in service end, realize in the following ways:
The heartbeat detection flow process of initiating for service end, service end is sent heartbeat detection request and identify generic sequence number in this request to client, client is received after heartbeat detection request, the sign sequence number value identical with sequence number in heartbeat detection request in the heartbeat detection response of returning, service end is received after heartbeat detection response in default heartbeat detection timing, sequence number is increased to predetermined interval value, and identify the sequence number after this renewal in the heartbeat detection request of next heartbeat detection cycle transmission.
Native system capable of dynamic is adjusted the number of times of the frequency that in heartbeat detection, request sends, and while making network state abnormal, initiates faster heartbeat detection next time, knows in time the normal state of network recovery.
Service end or client, in carrying out heartbeat detection process, are sent after heartbeat detection request to opposite equip., while not receiving the heartbeat detection response of opposite end in the default heartbeat detection timing of local terminal, reduce the duration that the request of local terminal heartbeat detection sends the cycle.
Service end or client are when repeating transmission heartbeat detection request number of times reaches default maximum retransmission and all do not receive heartbeat detection response in default heartbeat detection timing, and judgement connects extremely, nullify and connect corresponding user.
Specific embodiment
Service end is connected initialized process and comprises with client:
Step 201, the link block acquisition terminal user profile of step client, this comprises the data of the upper layer application needs such as terminal MAC Address, user name, Customs Assigned Number.Service end authentication submodule starts to monitor the user message of designated port.Service end user management submodule starts to monitor target message.
Step 202, the user profile that client connexon module is used an anonymous ID and carried collection is initiated registration request to service end.After this start a timer and wait for the response of service end, timer expiry resends without response.
Step 203, service end authentication submodule receives the laggard row data deciphering of user's registration message and user validation is carried out to verification.Verification failure is returned and is continued to monitor, verification by after the user ID parsing is verified, for anonymous ID and non-existent ID, all as new user's processing, be an ID of its distribution.The user who exists for ID upgrades and processes as user profile.
Step 204, service end authentication submodule sends to service end user management submodule by user registration/user updating message, and user management submodule upgrades Subscriber Queue according to the user profile in message.For this user starts heartbeat detection module, this module is responsible for the lasting connection of maintain customer end and service end.
Step 205, service end authentication submodule returns to a response message to client, carries this user's ID in message.
Step 206, the link block of client receives the user ID of resolving in message after response message and preserves, this ID is using always as this user's unique identification, even if follow-up network congestion causes the temporary transient off-line of user, while reconnecting, (this situation is considered as user and continues to connect) still used this ID, guarantees like this sustainable management of service end to user.
Step 207, client terminal start-up heartbeat detection module, the heartbeat detection module that this module and step 204 service end start echo mutually completing user continue be connected.The heartbeat detection module that step 204 and step 207 start is two-way authentication.
The testing process that service end is initiated heartbeat detection comprises:
Step 301, service end, for a client initialization heartbeat detection relevant parameter, comprises that it is 1 that this value of sequence number ST1(can be given tacit consent to initial value), heartbeat detection cycle, heartbeat detection timing length, default maximum retransmission.
Step 302, service end sends the heartbeat detection request containing the ST1 that transmits Sequence Number to client, starts heartbeat detection timer simultaneously.Client sends heartbeat detection response and identify the sequence number ST1 in this heartbeat detection request in this response to service end after this heartbeat detection request.
Step 303, service end judges whether to receive the heartbeat detection response of client before timer expiry, if receive execution step 304, if do not received, execution step 305.
Step 304, service end is received the heartbeat detection response of client before timer expiry, shows to connect normal between the two.Service end is re-set as initial value by heartbeat detection cycle and default maximum retransmission.For example, after sequence number ST1 is increased to predetermined interval value (1), the next transmission cycle continues to send heartbeat detection request.
Step 305, service end is not received the heartbeat detection response of client before timer expiry, the duration (for example the duration in this cycle being reduced by half) that reduces the local terminal heartbeat detection request transmission cycle adds 1 by number of retransmissions simultaneously, waits for that next heartbeat detection request transmission cycle retransmits heartbeat detection request.Service end will be initiated heartbeat request next time very soon like this.Service end checks whether number of retransmissions has reached default maximum retransmission after the request of each re-transmission heartbeat detection, while not reaching, continues to retransmit, and while reaching, service end judgement disconnecting, discharges this and connect corresponding user resources.
The testing process that client is initiated heartbeat detection comprises:
Step 401, client initialization, for the heartbeat detection relevant parameter of service end, comprises that it is 0 or 1 that this value of request serial number CT1(can be given tacit consent to initial value), heartbeat detection cycle, heartbeat detection timing length, default maximum retransmission.It is 1 that this value of service end initialization response sequence number ST2(can be given tacit consent to initial value).
Step 402, client sends sign has the heartbeat request of request serial number CT1 to service end, starts heartbeat detection timer simultaneously.
Step 403, service end is received after heartbeat detection request, judge when in this request, request serial number is less than or equal to it and safeguards response sequence, judge that this request is for effectively request, response sequence number is increased to predetermined interval value (for example 1), the response sequence number after identifying this upgrade in the heartbeat detection response of returning to client.
During client retransmits, need initiatively to carry out user profile and refresh, like this service end user profile that can upgrade in time after client network is congested.Descending in mobile radio communication (server is to terminal) communication bandwidth is higher, and ability to communicate is larger, and service end is also more up more easily sends to client by response message.Therefore in step 403, service end adopts aforesaid way can strengthen the accuracy rate of verification.
Step 404, client judges whether to receive the heartbeat detection response of service end before timer expiry, if receive execution step 405, if do not received, execution step 406.
Step 405, client is received the heartbeat detection response of service end before timer expiry, judge when in this response, response sequence number is greater than the request serial number of its maintenance, request serial number is upgraded to the value of response sequence for this reason number, and in the heartbeat detection request of next heartbeat detection cycle transmission, identify the request serial number after this renewal, and heartbeat detection cycle and default maximum retransmission are re-set as to initial value.Client judges when in this response, response sequence number is less than or equal to the request serial number of its maintenance, maintains request serial number, and identifies this request serial number in the heartbeat detection request of next heartbeat detection cycle transmission.
Step 406, client is not received the heartbeat detection response of service end before timer expiry, the duration (for example the duration in this cycle being reduced by half) that reduces the local terminal heartbeat detection request transmission cycle adds 1 by number of retransmissions simultaneously, waits for that next heartbeat detection request transmission cycle retransmits heartbeat detection request.Client checks whether number of retransmissions has reached default maximum retransmission after the request of each re-transmission heartbeat detection, while not reaching, continues to retransmit, and while reaching, client judgement disconnecting, discharges this and connect corresponding user resources.
It should be noted that, in the situation that not conflicting, the embodiment in the application and the feature in embodiment be combination in any mutually.
Certainly; the present invention also can have other various embodiments; in the situation that not deviating from spirit of the present invention and essence thereof; those of ordinary skill in the art can make according to the present invention various corresponding changes and distortion, but these corresponding changes and distortion all should belong to the protection range of the appended claim of the present invention.
One of ordinary skill in the art will appreciate that all or part of step in said method can come instruction related hardware to complete by program, described program can be stored in computer-readable recording medium, as read-only memory, disk or CD etc.Alternatively, all or part of step of above-described embodiment also can realize with one or more integrated circuits.Correspondingly, each the module/unit in above-described embodiment can adopt the form of hardware to realize, and also can adopt the form of software function module to realize.The present invention is not restricted to the combination of the hardware and software of any particular form.