Method and device for realizing state consistency of terminal and server, and storage medium
By using the target expected state of the server to modify the actual state of the terminal when comparing the status of the terminal and the server, the problems of long connection stability and message backlog are solved, and the state consistency between the terminal and the server is achieved and the user experience is improved.
Patent Information
- Application Number
- CN202311734121.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-15
- Publication Date
- 2024-10-22
AI Technical Summary
When the existing technology maintains consistent status between the terminal and the server, long connection stability requirements are high and the message backlog problem is difficult to solve, resulting in high research and development difficulties and poor user experience.
By using the target expected state of the server to modify the target actual state of the terminal when the comparison results between the expected signature and the actual signature are inconsistent, it ensures that the status of the terminal and the server are consistent, reduces the stability requirements for long connections, and avoids messages. Rapid switching of terminal status caused by backlog.
It achieves consistency between the status of the terminal and the server, reduces the difficulty of research and development, improves user experience, and avoids rapid switching of terminal status due to message backlog.
Smart Images

Figure CN118827482A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network communication technology, and in particular to a method, device and storage medium for achieving consistency between the states of a terminal and a server. Background Art
[0002] For many current application systems, the system needs to keep the status of the service side and the terminal consistent to ensure the accurate control of the terminal. In order to ensure the consistency of the status of the terminal and the server, the processing method of the prior art is as follows: First, optimize the long connection service, try to ensure the stability and availability of the long connection, mainly use heartbeat processing, connection keep alive, message caching, message retransmission and disconnection reconnection and other mechanisms to ensure the arrival of data when the long connection is available; Second, by caching messages, obtain the messages that need to be sent by the long connection during polling to achieve consistency of data status. However, the first method has high requirements for R&D code, and in some special cases, the long connection cannot be guaranteed to be established. When polling, there will be a gap period in the polling interval, and a large number of messages may be backlogged during the period; in the face of backlogged messages, if the means of integrating the same type of messages and taking the last message to use is adopted, it is difficult to implement message processing, and it is necessary to judge the timing of the message and whether certain processing can be discarded. The code requirement is high. If the backlogged messages are directly sent according to the timing, the terminal may switch between multiple states quickly, resulting in a poor user experience. Summary of the invention
[0003] Based on this, the present invention provides a method, device and storage medium for achieving consistency in the status of a terminal and a server. When the feature code associated with the target expected state and the feature code associated with the target actual state of the terminal are inconsistent, the terminal state can be modified according to the target expected state of the server to achieve consistency in the status of the terminal and the server. It does not have high requirements on the stability of long connections and will not generate too many backlogs of messages, thereby reducing the difficulty of research and development and improving user experience.
[0004] To achieve the above object, an embodiment of the present invention provides a method for achieving consistency between the states of a terminal and a server, which is applied to a terminal, and the method includes:
[0005] When the comparison result of the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server; wherein the expected feature code is the feature code associated with the target expected state of the server, and the actual feature code is the feature code associated with the target actual state of the terminal;
[0006] The target actual state of the terminal is modified according to the target expected state, so that the state of the terminal is consistent with that of the server.
[0007] As an improvement of the above solution, when the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server includes:
[0008] Receive the target expected state and expected feature code sent by the server through a long connection;
[0009] modifying the target actual state of the terminal according to the target expected state;
[0010] After the target actual state of the terminal is modified, generating the actual feature code according to the target actual state;
[0011] When the comparison result between the expected feature code and the actual feature code is inconsistent, sending state modification failure information to the server, so that the server sends the target expected state to the terminal again;
[0012] Receiving the target expected state sent again by the server;
[0013] The modifying the target actual state of the terminal according to the target expected state so that the state of the terminal is consistent with that of the server includes:
[0014] The target actual state of the terminal is modified according to the target expected state sent again by the server, so that the state of the terminal is consistent with that of the server.
[0015] As an improvement of the above solution, it also includes: when the comparison result of the expected feature code and the actual feature code is consistent, uploading the actual feature code to the server.
[0016] As an improvement of the above solution, when the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server also includes:
[0017] The target expected state is received from the server after executing the comparison task of the expected feature code and the actual feature code; wherein the server sends the target expected state when the comparison result of the comparison task is inconsistent.
[0018] As an improvement of the above solution, when the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server includes:
[0019] Initiate a status comparison request to the server, wherein the status comparison request carries the actual feature code;
[0020] receiving state maintenance information fed back by the server; wherein, when the comparison result between the actual feature code and the expected feature code is inconsistent, the state maintenance information carries the target expected state;
[0021] The modifying the target actual state of the terminal according to the target expected state so that the state of the terminal is consistent with that of the server includes:
[0022] When the state maintenance information carries the target expected state, the target actual state of the terminal is modified according to the target expected state so that the state of the terminal is consistent with that of the server.
[0023] As an improvement of the above scheme, the expected feature code is a comprehensive value of feature codes of all expected states in the expected state group of the server, the expected state group includes the target expected state and at least one other expected state, and the actual feature code is a comprehensive value of feature codes of all actual states in the actual state group of the terminal, the actual state group includes the target actual state and at least one other actual state.
[0024] As an improvement of the above solution, when the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server includes:
[0025] When the comparison result of the expected feature code and the actual feature code is inconsistent, if the comparison result of the feature code of the target expected state and the feature code of the target actual state is inconsistent, the target expected state sent by the service end is received.
[0026] As an improvement of the above solution, when the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server includes:
[0027] When the comparison result between the expected feature code and the actual feature code is inconsistent, receiving all expected states in the expected state group sent by the server;
[0028] The modifying the target actual state of the terminal according to the target expected state so that the state of the terminal is consistent with that of the server includes:
[0029] All actual states of the actual state group of the terminal are modified according to all expected states in the expected state group, so that the state of the terminal is consistent with that of the server.
[0030] As an improvement of the above solution, the feature code is a value of the fifth version of the message digest algorithm.
[0031] To achieve the above-mentioned purpose, an embodiment of the present invention further provides a device for achieving consistency between the states of a terminal and a server, which is applied to a server, and the method includes:
[0032] When the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal, so that the terminal modifies the target actual state of the terminal according to the target expected state;
[0033] The expected feature code is a feature code associated with the target expected state of the server, and the actual feature code is a feature code associated with the target actual state of the terminal.
[0034] As an improvement of the above solution, when the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state, includes:
[0035] Sending a target expected state and an expected feature code to the terminal in a long connection mode, so that the terminal modifies the target actual state of the terminal according to the target expected state;
[0036] Receiving state modification failure information fed back by the terminal; wherein the state modification failure information is generated by the terminal according to the inconsistency of the comparison result between the expected feature code and the actual feature code;
[0037] The target expected state is sent to the terminal again according to the state modification failure information.
[0038] As an improvement of the above solution, the method further includes: when a comparison result between the expected feature code and the actual feature code is consistent, receiving the actual feature code sent by the terminal.
[0039] As an improvement of the above solution, when the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state, further comprising:
[0040] If the comparison task is triggered, the expected feature code is compared with the actual feature code;
[0041] When the comparison result between the expected feature code and the actual feature code is inconsistent, a target expected state is sent to the terminal, so that the terminal modifies the target actual state of the terminal according to the target expected state.
[0042] As an improvement of the above solution, when the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state, includes:
[0043] receiving a status comparison request initiated by the terminal, wherein the status comparison request carries an actual feature code;
[0044] Comparing the actual feature code with the expected feature code;
[0045] When the comparison result between the actual feature code and the expected feature code is inconsistent, state maintenance information is fed back to the terminal so that the terminal modifies the target actual state of the terminal according to the state maintenance information; wherein the state maintenance information carries the target expected state.
[0046] As an improvement of the above scheme, the expected feature code is a comprehensive value of feature codes of all expected states in the expected state group of the server, the expected state group includes the target expected state and at least one other expected state, and the actual feature code is a comprehensive value of feature codes of all actual states in the actual state group of the terminal, the actual state group includes the target actual state and at least one other actual state.
[0047] As an improvement of the above solution, when the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state, includes:
[0048] When the comparison result between the expected feature code and the actual feature code is inconsistent, if the comparison result between the feature code of the target expected state and the feature code of the target actual state is inconsistent, the target expected state is sent to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state.
[0049] As an improvement of the above solution, when the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state, includes:
[0050] When the comparison result between the expected feature code and the actual feature code is inconsistent, all expected states in the expected state group are sent to the terminal, so that the terminal modifies all actual states in the actual state group of the terminal according to all expected states in the expected state group.
[0051] As an improvement of the above solution, the feature code is a value of the fifth version of the message digest algorithm.
[0052] To achieve the above purpose, an embodiment of the present invention further provides a device for achieving consistency between the states of a terminal and a server. The device, as a terminal, is used to execute the method for achieving consistency between the states of a terminal and a server as described in any of the above embodiments applied to a terminal.
[0053] To achieve the above purpose, an embodiment of the present invention further provides a device for achieving consistency between the states of a terminal and a server. The device serves as a server and is used to execute the method for achieving consistency between the states of a terminal and a server as described in any of the above embodiments applied to the server.
[0054] To achieve the above-mentioned purpose, an embodiment of the present invention also provides a device for achieving consistency in the status of a terminal and a server, comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, it implements the method for achieving consistency in the status of a terminal and a server as described in any of the above embodiments.
[0055] To achieve the above-mentioned purpose, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute a method for achieving consistency in the status of a terminal and a server as described in any of the above-mentioned embodiments.
[0056] Compared with the prior art, the method, device and storage medium for achieving consistency between the states of the terminal and the server disclosed in the embodiments of the present invention modify the target actual state of the terminal using the target expected state of the server to make the states of the terminal consistent with those of the server when the comparison results of the expected feature code and the actual feature code are inconsistent; wherein the expected feature code is the feature code associated with the target expected state of the server, and the actual feature code is the feature code associated with the target actual state of the terminal. It can be seen that the embodiments of the present invention achieve consistency between the states of the terminal and the server by modifying the state of the terminal according to the target expected state of the server when the feature code associated with the target expected state and the feature code associated with the target actual state of the terminal are inconsistent. The stability requirements for long connections are not high, and there will be no rapid switching of multiple states of the terminal due to the generation of too many backlogged messages, which reduces the difficulty of research and development and improves the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the technical solution of the present invention, the drawings required for use in the implementation mode will be briefly introduced below. Obviously, the drawings described below are only some implementation modes of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0058] Figure 1 It is a flowchart of a method for achieving consistency between the states of a terminal and a server provided by an embodiment of the present invention;
[0059] Figure 2 This is a schematic diagram of a process of a server actively modifying the status of a terminal provided by an embodiment of the present invention;
[0060] Figure 3 This is a flow chart of a server executing a scheduled task provided by an embodiment of the present invention;
[0061] Figure 4 It is a schematic diagram of a process of a terminal executing a guaranteed minimum task provided by an embodiment of the present invention;
[0062] Figure 5 It is a structural diagram of a device for achieving consistency between the states of a terminal and a server provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0063] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0064] See also Figure 1 , is a flow chart of a method for achieving consistency between the terminal and the server provided by an embodiment of the present invention. Specifically, the method for achieving consistency between the terminal and the server is applied to the terminal, and includes steps S1 to S2:
[0065] S1. When the comparison result of the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server; wherein the expected feature code is the feature code associated with the target expected state of the server, and the actual feature code is the feature code associated with the target actual state of the terminal;
[0066] S2. Modify the target actual state of the terminal according to the target expected state, so that the state of the terminal is consistent with that of the server.
[0067] It is worth noting that in this embodiment, a set of device states is set as the expected state on the server side. Optionally, the server side can also set another set of device states as the actual state. The server side finds the expected state that needs to be modified by responding to the terminal state modification instruction, that is, finds the target expected state, and then modifies the target expected state. The expected feature code is an identification code related to the target expected state, which needs to be generated according to the target expected state. When the target expected state changes, the expected feature code also needs to be recalculated. The actual state recorded by the server side is set according to the actual situation of the terminal. The actual feature code is an identification code related to the target actual state, which needs to be generated according to the target actual state. When the target actual state changes, the target actual state also needs to be recalculated. The generation algorithm of the expected feature code and the actual feature code uses the same set of algorithms. The use of feature codes is to simplify the complexity of message comparison. Generally, there are many types of data in the business. If the full field is compared every time, the pressure on the server or the terminal will be very large, so a relatively small and unique identifier needs to be generated to complete the comparison.
[0068] Exemplarily, before step S1, the server or terminal compares the expected feature code with the actual feature code in response to the state comparison instruction to obtain the comparison result. When the comparison result is inconsistent, it indicates that there is a risk of inconsistency between the target expected state and the target actual state. Therefore, the terminal needs to execute step S1 to receive the target expected state provided by the server, and then execute step S2 to modify the target actual state of the terminal according to the target expected state of the server to reduce the risk of inconsistency between the target expected state and the target actual state. Among them, the state comparison instruction can be triggered by the terminal or by the server. The method can be executed in different tasks, such as in the task of the server actively modifying the state of the terminal through a long connection in response to the state modification instruction triggered by the user, or in the task of the server periodically comparing the expected state with the actual state, or in the task of the terminal actively comparing the expected state with the actual state, etc., which are not specifically limited here. It can be understood that the embodiment of the present invention avoids the influence of timing on the terminal by maintaining the final state consistency, and reduces the pressure of each comparison by extracting key information of the parameters to calculate the feature code.
[0069] Compared with the prior art, the embodiment of the present invention achieves consistency between the terminal and the server by modifying the terminal state according to the target expected state of the server when the feature code associated with the target expected state and the feature code associated with the target actual state of the terminal are inconsistent. It does not require high stability of long connections and will not cause the terminal to switch between multiple states quickly due to the generation of too many backlogs of messages, thereby reducing the difficulty of research and development and improving user experience.
[0070] In one implementation, when the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server includes:
[0071] Receive the target expected state and expected feature code sent by the server through a long connection;
[0072] modifying the target actual state of the terminal according to the target expected state;
[0073] After the target actual state of the terminal is modified, generating the actual feature code according to the target actual state;
[0074] When the comparison result between the expected feature code and the actual feature code is inconsistent, sending state modification failure information to the server, so that the server sends the target expected state to the terminal again;
[0075] Receiving the target expected state sent again by the server;
[0076] The modifying the target actual state of the terminal according to the target expected state so that the state of the terminal is consistent with that of the server includes:
[0077] The target actual state of the terminal is modified according to the target expected state sent again by the server, so that the state of the terminal is consistent with that of the server.
[0078] For example, see Figure 2 , Figure 2The present invention provides a flow chart of a process of a server actively modifying the state of a terminal, wherein a message sender uses a service initiation function to send a state modification request for a specified terminal to a message service of a server through a service distribution function of a reverse proxy, and the message service determines a target expected state according to the state modification request, updates the target expected state maintained by the server, calculates an expected feature code associated with the modified target expected state, and sends the modified target expected state and its associated expected feature code to the specified terminal through a terminal-side distribution function of a long connection management of the server; the terminal modifies the actual state of the target according to the target expected state, and updates the target expected state according to the modified target expected state. The actual status generates an actual feature code. If the modification is completed, the actual feature code and the target feature code are compared. If the two are consistent, it means that the terminal modification is successful. The information of successful modification is fed back to the server side through the long connection management, so that the server can update the target actual status stored on the server according to the target expected status. If the two are inconsistent or the terminal has not completed the modification, it means that the terminal modification has failed. The terminal will feed back the information of modification failure to the server through the long connection management or http interface, so that the server can send the target expected status to the terminal again, prompting the terminal to execute the modification task again, until the status of the terminal is consistent with that of the server or the number of repeated sends by the server reaches the upper limit.
[0079] In one embodiment, the method further includes: when the comparison result of the expected feature code and the actual feature code is consistent, uploading the actual feature code to the server. Optionally, when the comparison result of the expected feature code and the actual feature code is consistent, the server can copy the expected feature code to the actual feature code managed by the server.
[0080] In one embodiment, when the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server also includes:
[0081] The target expected state is received from the server after executing the comparison task of the expected feature code and the actual feature code; wherein the server sends the target expected state when the comparison result of the comparison task is inconsistent.
[0082] For example, see Figure 3The process diagram of the server executing the scheduled task shown in the figure, the server will start the corresponding scheduled task, and when the message fingerprint information (such as the actual feature code) is recorded in the corresponding queue according to the sending time of the terminal sending data (if the terminal has multiple messages, only the last one is retained), when the scheduled task is started, the server will periodically compare the expected feature code with the actual feature code. If the comparison results are inconsistent, the corresponding terminal will be notified through the corresponding long connection, and the target expected state will be sent to the corresponding terminal. The terminal will modify the state according to the received target expected state. Optionally, when the terminal sends the target expected state, the expected feature value will be sent together, so that the terminal will compare the updated actual feature code with the expected feature code after completing the state modification. The terminal will feedback the current state of the terminal to the server according to the comparison result, so as to maintain the actual state stored by the server. This scheduled task can ensure that after the data about the target expected state sent by the server to the terminal is lost, the corresponding terminal side state information and the expected state of the service side can still be consistent in the future.
[0083] In one implementation, when the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server includes:
[0084] Initiate a status comparison request to the server, wherein the status comparison request carries the actual feature code;
[0085] receiving state maintenance information fed back by the server; wherein, when the comparison result between the actual feature code and the expected feature code is inconsistent, the state maintenance information carries the target expected state;
[0086] The modifying the target actual state of the terminal according to the target expected state so that the state of the terminal is consistent with that of the server includes:
[0087] When the state maintenance information carries the target expected state, the target actual state of the terminal is modified according to the target expected state so that the state of the terminal is consistent with that of the server.
[0088] For example, see Figure 4The process diagram of the terminal executing the guaranteed task is shown in the figure. The service provides a corresponding status query mechanism. When the long connection heartbeat fails and the connection is established, the terminal's polling guaranteed task calls the status query interface and sends an http message to the reverse proxy, so that the reverse proxy sends a related message (the message carries the actual feature code) to the message service of the server. The message service processes the message, parses the actual feature code, and compares it with the expected feature code of the corresponding target expected state. If the comparison result is inconsistent, the server sends a state maintenance message carrying the target expected state to the terminal. The terminal parses the received state maintenance message to obtain the target expected state, so as to modify the state of the terminal, and after the modification, the modification is fed back to the server. This mechanism can ensure that the state of the terminal can be guaranteed to be maintained to the expected normal state within a certain time (the time interval is mainly determined by the mentality interval, the rotation guaranteed interval, and the rotation time of the back-end scheduled task, mainly the time interval for the terminal to call the status query when the long connection is unavailable).
[0089] In one embodiment, the expected feature code is a comprehensive value of feature codes of all expected states in an expected state group of the server, the expected state group includes the target expected state and at least one other expected state, and the actual feature code is a comprehensive value of feature codes of all actual states in an actual state group of the terminal, the actual state group includes the target actual state and at least one other actual state.
[0090] Specifically, the terminal has many different types of services, such as camera switch, microphone switch, visible data range, whether other users are currently online, current interface style, etc. In order to speed up the determination of whether the status of the terminal and the server are consistent, see the grouping of services. The status of all services can be grouped into one status group or divided into multiple status groups. Taking the status of all services as one status group and the feature code as MD5 (Message Digest Algorithm 5) value as an example, the lightweight data exchange format (JavaScript Object Notation, JSON) data of the terminal is first divided by service, and the keyword key in each group is sorted according to the ASCII code. After sorting, the value corresponding to the corresponding key is taken out in order, and the value is spliced into a string in the order of taking out. The system calculates the corresponding MD5 value of each service according to the string and records it, and then splices the corresponding MD5 value in the order of division to calculate the final MD5 value (actual feature code / expected feature code). By comparing the final MD5 value, it can be quickly determined whether there is an actual state in the actual state group that is inconsistent with the expected state in the expected state group.
[0091] It is worth noting that the calculation method of the comprehensive value of the feature codes of all actual states is not limited to the value splicing method of the above-mentioned states of each business, and can be set according to actual conditions, such as adding the feature codes of each actual state to obtain a comprehensive value. The specific calculation method of the comprehensive value is not limited here.
[0092] Optionally, when the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server includes:
[0093] When the comparison result of the expected feature code and the actual feature code is inconsistent, if the comparison result of the feature code of the target expected state and the feature code of the target actual state is inconsistent, the target expected state sent by the service end is received.
[0094] Exemplarily, assuming that the type of the feature code is MD5, when the server or terminal is performing a status comparison, the final MD5 will be compared first. If they are consistent, it is determined that all corresponding states of the current actual state group and the expected state group are consistent. If they are inconsistent, the final MD5 value will be split separately, and the MD5 value of each service will be compared separately, and the services with different MD5 values will be found to obtain the expected state (target expected state) of the service from the server, and the target actual state of the terminal will be modified. After the modification is completed, the MD5 value of the service (the feature code of the actual state of the service) will be recalculated and compared with the MD5 received before (the feature code of the expected state of the service). After consistency, the MD5 of the actual state of each service will be used for splicing, and the final MD5 will be recalculated and the consistency comparison will be completed. The above comparison and modification process will be repeated until the actual feature code is consistent with the expected feature code.
[0095] It is understandable that the feature code comparison method and state modification method of the implementation mode of the present invention can be applied to different tasks, such as the task of the server actively modifying the state of the terminal through a long connection in response to the state modification instruction triggered by the user, or the task of the server periodically comparing the expected state with the actual state, or the task of the terminal actively comparing the expected state with the actual state, etc. The implementation mode of the present invention calculates the feature codes of the states of different services respectively and splices them, first compares the total feature code, and then splits and compares the total feature code when the comparison results are inconsistent, thereby reducing the time consumption of comparison when there are many business state values, and can quickly locate the corresponding differences, so as to achieve fast and accurate state synchronization of the terminal side state.
[0096] Optionally, when the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server includes:
[0097] When the comparison result between the expected feature code and the actual feature code is inconsistent, receiving all expected states in the expected state group sent by the server;
[0098] The modifying the target actual state of the terminal according to the target expected state so that the state of the terminal is consistent with that of the server includes:
[0099] All actual states of the actual state group of the terminal are modified according to all expected states in the expected state group, so that the state of the terminal is consistent with that of the server.
[0100] Exemplarily, assuming that the type of the feature code is MD5, when the server or terminal is performing a state comparison, it will first compare the final MD5 (i.e., compare the actual feature code with the expected feature code). If they are consistent, it is determined that all corresponding states of the current actual state group and the expected state group are consistent. If they are inconsistent, it means that at least one state in the actual state group is inconsistent with the corresponding state in the expected feature group. Therefore, the server sends all the expected states in the expected state group to the terminal, and the terminal modifies the state according to the received expected state, and repeats the above comparison and modification process until the actual feature code is consistent with the expected feature code.
[0101] It can be understood that the feature code comparison method and the state modification method of the implementation mode of the present invention can be applied to different tasks, such as the task of actively modifying the state of the terminal through a long connection method in response to a state modification instruction triggered by the user on the server side, or the task of periodically comparing the expected state and the actual state on the server side, or the task of actively comparing the expected state and the actual state on the terminal, etc.
[0102] In one implementation, the feature code is a message digest algorithm version 5 value.
[0103] Specifically, in this embodiment, the MD5 algorithm is used as a method similar to an electronic signature. The MD5 algorithm can generate a unique "digital fingerprint" for the actual state / expected state. With the help of this "digital fingerprint", the consistency of the actual state and the expected state can be determined by checking whether the MD5 values of the actual state and the expected state are consistent, and then the actual state of the terminal can be maintained accordingly based on the comparison result.
[0104] Compared with the prior art, the embodiment of the present invention mainly ensures the final message consistency of the terminal. The server provides a status (the status is mainly formulated according to business needs, such as camera switch, microphone switch, visible data range, whether other users are currently online, current interface style and other business-related information) query http interface and terminal-side status information maintenance, and mainly maintains two sets of status, one is the expected state, and the other is the current feedback state (actual state). The expected state will be modified when a message that needs to modify the state arrives at the server. This state mainly represents the state of the terminal maintained by the server according to the message. This state is the final state that the terminal should achieve. The current feedback state will be modified when the terminal modifies the state according to the received message and feeds back the current state information to the server. The current feedback state mainly represents the state of the terminal obtained by the server. Furthermore, the status information is classified according to the business, and the corresponding MD5 values are calculated respectively. The MD5 values of each category are then added together to calculate a final MD5 value. When the actual status of the terminal is maintained, it is only necessary to compare the final MD5 value first. If there is any inconsistency, the MD5 of each category will be compared, and the expected status corresponding to the inconsistent MD5 of each category will be synchronized to the terminal, or when the final MD5 value comparison is inconsistent, all expected status associated with the final MD5 value will be synchronized to the terminal, and the terminal will modify the corresponding status, which reduces the complexity of status comparison and reduces the cost of terminal status maintenance.
[0105] The embodiment of the present invention further provides a method for achieving consistency between the states of a terminal and a server, which is applied to the server, and the method includes:
[0106] When the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal, so that the terminal modifies the target actual state of the terminal according to the target expected state;
[0107] The expected feature code is a feature code associated with the target expected state of the server, and the actual feature code is a feature code associated with the target actual state of the terminal.
[0108] In one embodiment, when the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state includes:
[0109] Sending a target expected state and an expected feature code to the terminal in a long connection mode, so that the terminal modifies the target actual state of the terminal according to the target expected state;
[0110] Receiving state modification failure information fed back by the terminal; wherein the state modification failure information is generated by the terminal according to the inconsistency of the comparison result between the expected feature code and the actual feature code;
[0111] The target expected state is sent to the terminal again according to the state modification failure information.
[0112] In one embodiment, the method further includes: when a comparison result between the expected feature code and the actual feature code is consistent, receiving the actual feature code sent by the terminal.
[0113] In one embodiment, when the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state, further includes:
[0114] If the comparison task is triggered, the expected feature code is compared with the actual feature code;
[0115] When the comparison result between the expected feature code and the actual feature code is inconsistent, a target expected state is sent to the terminal, so that the terminal modifies the target actual state of the terminal according to the target expected state.
[0116] In one embodiment, when the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state includes:
[0117] receiving a status comparison request initiated by the terminal, wherein the status comparison request carries an actual feature code;
[0118] Comparing the actual feature code with the expected feature code;
[0119] When the comparison result between the actual feature code and the expected feature code is inconsistent, state maintenance information is fed back to the terminal so that the terminal modifies the target actual state of the terminal according to the state maintenance information; wherein the state maintenance information carries the target expected state.
[0120] In one embodiment, the expected feature code is a comprehensive value of feature codes of all expected states in an expected state group of the server, the expected state group includes the target expected state and at least one other expected state, and the actual feature code is a comprehensive value of feature codes of all actual states in an actual state group of the terminal, the actual state group includes the target actual state and at least one other actual state.
[0121] In one embodiment, when the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state includes:
[0122] When the comparison result between the expected feature code and the actual feature code is inconsistent, if the comparison result between the feature code of the target expected state and the feature code of the target actual state is inconsistent, the target expected state is sent to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state.
[0123] In one embodiment, when the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state includes:
[0124] When the comparison result between the expected feature code and the actual feature code is inconsistent, all expected states in the expected state group are sent to the terminal, so that the terminal modifies all actual states in the actual state group of the terminal according to all expected states in the expected state group.
[0125] In one implementation, the feature code is a message digest algorithm version 5 value.
[0126] It is worth noting that the working process of the method for achieving consistency between the terminal and the server state applied to the server in an embodiment of the present invention can refer to the specific working process of the server of the method for achieving consistency between the terminal and the server state described in the above embodiment applied to the terminal, which will not be repeated here.
[0127] Compared with the prior art, the embodiment of the present invention achieves consistency between the terminal and the server by modifying the terminal state according to the target expected state of the server when the feature code associated with the target expected state and the feature code associated with the target actual state of the terminal are inconsistent. It does not require high stability of long connections and will not cause the terminal to switch between multiple states quickly due to the generation of too many backlogs of messages, thereby reducing the difficulty of research and development and improving user experience.
[0128] An embodiment of the present invention further provides a device for achieving consistency between the states of a terminal and a server. The device, as a terminal, is used to execute the method for achieving consistency between the states of a terminal and a server as described in any of the above embodiments applied to a terminal.
[0129] An embodiment of the present invention further provides a device for achieving consistency between the states of a terminal and a server. The device serves as a server and is used to execute the method for achieving consistency between the states of a terminal and a server as described in any of the above embodiments applied to the server.
[0130] An embodiment of the present invention also provides a system for achieving consistency in the status of a terminal and a server, the system comprising a terminal and a server, the terminal being used to execute a method for achieving consistency in the status of a terminal and a server as described in any of the above embodiments applied to the terminal, and the server being used to execute a method for achieving consistency in the status of a terminal and a server as described in any of the above embodiments applied to the server.
[0131] Compared with the prior art, the device and system for achieving consistency between the states of the terminal and the server disclosed in the embodiments of the present invention achieve consistency between the states of the terminal and the server by modifying the state of the terminal according to the target expected state of the server when the feature code associated with the target expected state and the feature code associated with the target actual state of the terminal are inconsistent. It does not require high stability of long connections and does not cause the terminal to quickly switch between multiple states due to the generation of too many backlogs of messages, thereby reducing the difficulty of research and development and improving user experience.
[0132] See also Figure 5 The embodiment of the present invention further provides a device for achieving consistency between the terminal and the server, comprising a processor 21, a memory 22, and a computer program stored in the memory 22 and configured to be executed by the processor 21. When the processor 21 executes the computer program, the steps in the above-mentioned method embodiment for achieving consistency between the terminal and the server are implemented, for example Figure 1 or, the processor 21 implements the functions of each module in the above-mentioned device embodiments when executing the computer program.
[0133] Exemplarily, the computer program may be divided into one or more modules, which are stored in the memory 22 and executed by the processor 21 to complete the present invention. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program in the device for achieving consistency between the terminal and the server. For example, the computer program may be divided into multiple modules.
[0134] The specific working process of each module can refer to the working process of the device for achieving consistency between the terminal and the server described in the above embodiment, and will not be repeated here.
[0135] The device for achieving consistency between the terminal and the server can be a desktop computer, a notebook, a PDA, a cloud server, or other device for computing and achieving consistency between the terminal and the server. The device for achieving consistency between the terminal and the server can include, but is not limited to, a processor 21 and a memory 22. Those skilled in the art can understand that the device for achieving consistency between the terminal and the server can also include an input / output device, a network access device, a bus, etc.
[0136] The processor 21 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor 21 is the control center of the device for achieving consistency between the terminal and the server, and uses various interfaces and lines to connect the various parts of the device for achieving consistency between the terminal and the server.
[0137] The memory 22 can be used to store the computer program and / or module. The processor 21 realizes various functions of the device for realizing the consistency of the terminal and the server state by running or executing the computer program and / or module stored in the memory 22 and calling the data stored in the memory 22. The memory 22 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone, etc. In addition, the memory 22 can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0138] Wherein, if the module for integrating the device for achieving the consistency of the terminal and the server status is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor 21. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc.
[0139] The above is a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several improvements and modifications without departing from the principle of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A method for achieving consistency between the terminal and the server state, It is characterized in that Applied to a terminal, the method comprises: When the comparison result of the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server; wherein the expected feature code is the feature code associated with the target expected state of the server, and the actual feature code is the feature code associated with the target actual state of the terminal; The target actual state of the terminal is modified according to the target expected state, so that the state of the terminal is consistent with that of the server.
2. The method for achieving consistency between the terminal and the server as claimed in claim 1, It is characterized in that When the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server includes: Receive the target expected state and expected feature code sent by the server through a long connection; modifying the target actual state of the terminal according to the target expected state; After the target actual state of the terminal is modified, generating the actual feature code according to the target actual state; When the comparison result between the expected feature code and the actual feature code is inconsistent, sending state modification failure information to the server, so that the server sends the target expected state to the terminal again; Receiving the target expected state sent again by the server; The modifying the target actual state of the terminal according to the target expected state so that the state of the terminal is consistent with that of the server includes: The target actual state of the terminal is modified according to the target expected state sent again by the server, so that the state of the terminal is consistent with that of the server.
3. The method for achieving consistency between the terminal and the server as claimed in claim 2, It is characterized in that Also includes: When the comparison result between the expected feature code and the actual feature code is consistent, the actual feature code is uploaded to the server.
4. The method for achieving consistency between the terminal and the server as claimed in claim 3, It is characterized in that When the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server, further comprising: The target expected state is received from the server after executing the comparison task of the expected feature code and the actual feature code; wherein the server sends the target expected state when the comparison result of the comparison task is inconsistent.
5. The method for achieving consistency between the terminal and the server as claimed in claim 1, It is characterized in that When the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server includes: Initiate a status comparison request to the server, wherein the status comparison request carries the actual feature code; receiving state maintenance information fed back by the server; wherein, when the comparison result between the actual feature code and the expected feature code is inconsistent, the state maintenance information carries the target expected state; The modifying the target actual state of the terminal according to the target expected state so that the state of the terminal is consistent with that of the server includes: When the state maintenance information carries the target expected state, the target actual state of the terminal is modified according to the target expected state so that the state of the terminal is consistent with that of the server.
6. The method for achieving consistency between the terminal and the server as claimed in any one of claims 1 to 5, It is characterized in that The expected feature code is a comprehensive value of feature codes of all expected states in the expected state group of the server, the expected state group includes the target expected state and at least one other expected state, and the actual feature code is a comprehensive value of feature codes of all actual states in the actual state group of the terminal, the actual state group includes the target actual state and at least one other actual state.
7. The method for achieving consistency between the terminal and the server as claimed in claim 6, It is characterized in that When the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server includes: When the comparison result of the expected feature code and the actual feature code is inconsistent, if the comparison result of the feature code of the target expected state and the feature code of the target actual state is inconsistent, the target expected state sent by the service end is received.
8. The method for achieving consistency between the terminal and the server as claimed in claim 6, It is characterized in that When the comparison result between the expected feature code and the actual feature code is inconsistent, receiving the target expected state sent by the server includes: When the comparison result between the expected feature code and the actual feature code is inconsistent, receiving all expected states in the expected state group sent by the server; The modifying the target actual state of the terminal according to the target expected state so that the state of the terminal is consistent with that of the server includes: All actual states of the actual state group of the terminal are modified according to all expected states in the expected state group, so that the state of the terminal is consistent with that of the server.
9. The method for achieving consistency between the terminal and the server as claimed in claim 1, It is characterized in that The feature code is the value of the fifth version of the message digest algorithm.
10. A method for achieving consistency between the terminal and the server state, It is characterized in that Applied to the server, the method includes: When the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal, so that the terminal modifies the target actual state of the terminal according to the target expected state; The expected feature code is a feature code associated with the target expected state of the server, and the actual feature code is a feature code associated with the target actual state of the terminal.
11. The method for achieving consistency between the terminal and the server as claimed in claim 10, It is characterized in that When the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state, includes: Sending a target expected state and an expected feature code to the terminal in a long connection mode, so that the terminal modifies the target actual state of the terminal according to the target expected state; Receiving state modification failure information fed back by the terminal; wherein the state modification failure information is generated by the terminal according to the inconsistency of the comparison result between the expected feature code and the actual feature code; The target expected state is sent to the terminal again according to the state modification failure information.
12. The method for achieving consistency between the terminal and the server as claimed in claim 11, It is characterized in that Also includes: When the comparison result between the expected feature code and the actual feature code is consistent, the actual feature code sent by the terminal is received.
13. The method for achieving consistency between the terminal and the server as claimed in claim 12, It is characterized in that When the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state, further comprising: If the comparison task is triggered, the expected feature code is compared with the actual feature code; When the comparison result between the expected feature code and the actual feature code is inconsistent, a target expected state is sent to the terminal, so that the terminal modifies the target actual state of the terminal according to the target expected state.
14. The method for achieving consistency between the terminal and the server as claimed in claim 10, It is characterized in that When the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state, includes: receiving a status comparison request initiated by the terminal, wherein the status comparison request carries an actual feature code; Comparing the actual feature code with the expected feature code; When the comparison result between the actual feature code and the expected feature code is inconsistent, state maintenance information is fed back to the terminal so that the terminal modifies the target actual state of the terminal according to the state maintenance information; wherein the state maintenance information carries the target expected state.
15. The method for achieving consistency between the terminal and the server as claimed in any one of claims 10 to 14, It is characterized in that The expected feature code is a comprehensive value of feature codes of all expected states in the expected state group of the server, the expected state group includes the target expected state and at least one other expected state, and the actual feature code is a comprehensive value of feature codes of all actual states in the actual state group of the terminal, the actual state group includes the target actual state and at least one other actual state.
16. The method for achieving consistency between the terminal and the server as claimed in claim 15, It is characterized in that When the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state, includes: When the comparison result between the expected feature code and the actual feature code is inconsistent, if the comparison result between the feature code of the target expected state and the feature code of the target actual state is inconsistent, the target expected state is sent to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state.
17. The method for achieving consistency between the terminal and the server as claimed in claim 15, It is characterized in that When the comparison result between the expected feature code and the actual feature code is inconsistent, sending the target expected state to the terminal so that the terminal modifies the target actual state of the terminal according to the target expected state, includes: When the comparison result between the expected feature code and the actual feature code is inconsistent, all expected states in the expected state group are sent to the terminal, so that the terminal modifies all actual states in the actual state group of the terminal according to all expected states in the expected state group.
18. The method for achieving consistency between the terminal and the server as claimed in claim 10, It is characterized in that The feature code is the value of the fifth version of the message digest algorithm.
19. A device for achieving consistency between the terminal and the server. It is characterized in that The device is used as a terminal to execute the method for achieving consistency between the terminal and the server as described in any one of claims 1 to 9.
20. A device for achieving consistency between the terminal and the server. It is characterized in that The device serves as a server, and is used to execute the method for achieving consistency between the states of the terminal and the server as described in any one of claims 10 to 18.
21. A device for achieving consistency between the terminal and the server. It is characterized in that It comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, and when the processor executes the computer program, it implements the method for achieving consistency of terminal and server status as described in any one of claims 1 to 18.
22. A computer-readable storage medium, It is characterized in that The computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the method for achieving consistency in status between a terminal and a server as described in any one of claims 1 to 18.
Citation Information
Patent Citations
Method and device for acquiring on-line state of terminal
CN105515900A
Method and system for updating configuration file, client and server
CN106341244A
Remote file verification method and device and computer readable storage medium
CN113422831A
Method for realizing data slow synchronization and system thereof
CN1852160A
