CN114221922A - Message processing method and device, electronic equipment and readable storage medium - Google Patents

Message processing method and device, electronic equipment and readable storage medium Download PDF

Info

Publication number
CN114221922A
CN114221922A CN202111528658.6A CN202111528658A CN114221922A CN 114221922 A CN114221922 A CN 114221922A CN 202111528658 A CN202111528658 A CN 202111528658A CN 114221922 A CN114221922 A CN 114221922A
Authority
CN
China
Prior art keywords
message
list
message list
processed
client
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111528658.6A
Other languages
Chinese (zh)
Inventor
周焓
张峰
李哲
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chongqing Qiyi Tianxia Technology Co ltd
Original Assignee
Chongqing Qiyi Tianxia Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chongqing Qiyi Tianxia Technology Co ltd filed Critical Chongqing Qiyi Tianxia Technology Co ltd
Priority to CN202111528658.6A priority Critical patent/CN114221922A/en
Publication of CN114221922A publication Critical patent/CN114221922A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L51/00User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail
    • H04L51/04Real-time or near real-time messaging, e.g. instant messaging [IM]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L51/00User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail
    • H04L51/07User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail characterised by the inclusion of specific contents
    • H04L51/18Commands or executable codes

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The embodiment of the invention provides a message processing method, a message processing device, electronic equipment and a readable storage medium. The method comprises the following steps: sequencing all messages received in the current time period according to the message ID to generate a new message list; intercepting a part of message list from the displayed message list to serve as a to-be-processed message list, wherein messages in the displayed message list are arranged according to the message ID sequence; comparing the message ID in the new message list with the message ID in the message list to be processed, identifying the message ID which does not exist in the message list to be processed from the new message list, and identifying the insertion position in the message list to be processed; and inserting the message corresponding to the identified message ID into an insertion position in the message list to be displayed, generating a message list to be displayed, and displaying each message in the message list to be displayed in the next time period. The method of the embodiment of the invention ensures the sequential display of the messages in the real-time chat process.

Description

Message processing method and device, electronic equipment and readable storage medium
Technical Field
The present invention relates to the field of message processing technologies, and in particular, to a message processing method and apparatus, an electronic device, and a readable storage medium.
Background
In a real-time chat scenario, network environments of both information receiving and sending parties and a server side may be complex, and when the network environments of the receiving and sending parties or the network environment of the server side fluctuate, a problem of disorder of chat messages may occur. In addition, the server application has instability, and when the number of chat users connected to the server is suddenly increased or the server has software and hardware failures, the problem of message disorder can also be caused.
Disclosure of Invention
The embodiment of the invention aims to provide a message processing method, a message processing device, electronic equipment and a readable storage medium, so as to avoid the problem of message disorder in the real-time chat process. The specific technical scheme is as follows:
in a first aspect of the embodiments of the present invention, a message processing method is first provided, where the message processing method is applied to a system including a first client, a second client, and a server, where the first client and the second client perform message interaction through the server, and the method is executed in the first client, where the method includes:
sequencing all messages received in the current time period according to the message ID to generate a new message list;
intercepting a part of message list from an already displayed message list to serve as a to-be-processed message list, wherein messages in the already displayed message list are arranged according to the message ID sequence, the arrangement sequence of the messages in the already displayed message list is the same as that of the messages in the new message list, the first message ID in the to-be-processed message list is smaller than the first message ID in the new message list, and the last message ID in the to-be-processed message list is the last message ID in the already displayed message list;
comparing the message IDs in the new message list with the message IDs in the to-be-processed message list, identifying from the new message list the message IDs that are not present in the to-be-processed message list, and identifying an insertion position in the to-be-processed message list;
inserting the message corresponding to the identified message ID into the insertion position in the message list to be processed, and generating a message list to be displayed;
and displaying each message in the message list to be displayed in the next time period.
In a second aspect of the present invention, there is also provided a message processing apparatus, applied to a system including a first client, a second client, and a server, where the first client and the second client perform message interaction through the server, the apparatus is disposed at the first client, and the apparatus includes:
the generating module is used for sequencing all the messages received in the current time period according to the message ID and generating a new message list;
an intercepting module, configured to intercept a part of a message list from an already displayed message list to serve as a to-be-processed message list, where messages in the already displayed message list are arranged according to the message ID sequence, the arrangement sequence of the messages in the already displayed message list is the same as the arrangement sequence of the messages in the new message list, a first message ID in the to-be-processed message list is smaller than a first message ID in the new message list, and a last message ID in the to-be-processed message list is a last message ID in the already displayed message list;
a comparison module, configured to compare the message IDs in the new message list with the message IDs in the to-be-processed message list, identify, from the new message list, a message ID that is not present in the to-be-processed message list, and identify an insertion position in the to-be-processed message list;
the inserting module is used for inserting the message corresponding to the identified message ID into the inserting position in the message list to be processed to generate a message list to be displayed;
and the display module is used for displaying each message in the message list to be displayed in the next time period.
In a third aspect implemented by the present invention, there is also provided an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where the computer program, when executed by the processor, implements the steps of the message processing method according to the first aspect of the embodiment of the present invention.
In a fourth aspect implemented by the present invention, there is also provided a computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the steps of the message processing method according to the first aspect of the embodiment of the present invention.
By adopting the message processing method provided by the embodiment of the invention, each message received in the current time period is sequenced according to the message ID to generate the new message list, and because the messages in the displayed message list are arranged according to the message ID sequence, and the message arrangement sequence in the displayed message list is the same as the message arrangement sequence in the new message list, the messages in the message list to be processed intercepted from the displayed message list are also arranged according to the message ID sequence, and the arrangement rule of the messages in the message list to be processed is the same as that in the new message list. Comparing the message ID in the new message list with the message ID in the message list to be processed, identifying the message ID which does not exist in the message list to be processed in the new message list, identifying the insertion position in the message list to be processed, inserting the message corresponding to the message ID which is identified not exist in the message list to be processed into the correct insertion position in the message list to be processed, so that the message in the new message list can be inserted into the message list to be processed at the correct insertion position, thereby realizing the correct combination of the two message lists, generating the message list to be displayed, realizing that the messages in the message list to be displayed are also displayed according to the message ID sequence arrangement, and avoiding the message disorder problem in the real-time chatting process.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments of the present invention will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without inventive labor.
FIG. 1 is a schematic diagram of an application scenario according to an embodiment of the present invention;
FIG. 2 is a flow chart illustrating a message processing method according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating a message queue according to an embodiment of the present invention;
FIG. 4 is a flow chart illustrating a message determination method according to an embodiment of the present invention;
FIG. 5 is a flow chart illustrating a message comparison method according to an embodiment of the present invention;
FIG. 6 is a flow chart illustrating a message compensation method according to an embodiment of the present invention;
fig. 7 is a flow chart illustrating a method of message delivery acknowledgement according to an embodiment of the invention;
FIG. 8 is a message interaction diagram illustrating an embodiment of the present invention;
fig. 9 is a block diagram of a message processing apparatus according to an embodiment of the present invention;
fig. 10 is a schematic diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Due to network fluctuation or instability of a server, the problem of message disorder of chat messages received by two chat parties may occur in a real-time chat scene. For example, the sequence of messages received by the client is not the sequence of messages actually sent by the server (or corresponding clients) due to various reasons such as network fluctuation or instability of the server, and the client is still shown according to the sequence of the messages received by the client, so that the messages shown by the client are out of order, for example, the sequence of the shown messages is 3 → 5 → 1; when the client receives the messages in the next time period, the sequence of the messages is as follows: 7 → 2 → 6, and the client still presents the messages according to the logic of presenting the received messages in the receiving order, the order of the presented messages at this time becomes 3 → 5 → 1 → 7 → 2 → 6, further resulting in the problem of the disorder of the presented messages of the client.
To at least partially solve one or more of the above problems and other potential problems, an embodiment of the present invention provides a message processing method, which arranges received messages in a message ID order to generate a new message list, determines a to-be-processed message list from displayed messages arranged in the message ID order according to message IDs in the new message list, and compares the new message list with the to-be-processed message list
Among the message IDs, identifying the message ID not present in the list of pending messages in the new message list and
the correct insertion position of the message corresponding to the message ID in the message list to be processed is inserted according to the correct insertion position
The message corresponding to the message ID which does not exist in the message list to be processed is inserted into the message list to be processed at the entry position so as to generate the message list to be displayed for message display, thereby ensuring that the messages can be displayed in sequence from beginning to end in the real-time chat process.
Fig. 1 is a schematic diagram of an application scenario according to an embodiment of the present invention. As shown in fig. 1, an application scenario of the present embodiment is a system 130 including a server 100, a first client 110, and a second client 120, where the server 100 is in communication connection with the first client 110 and the second client 120, respectively, and the first client 110 and the second client 120 perform message interaction through a service segment 100. In the chat process, the first client 110 and the second client 120 are connected to the server 100 through message transmission channels, respectively, and after a message sent by the first client 110 (or the second client 120) reaches the server 110 through the message transmission channels, the server 110 serves as a relay station to distribute the received message to the corresponding second client 120 (or the first client 110) through the message transmission channels, thereby implementing sending and receiving of the message.
In this embodiment, the client may refer to a program providing a local service for a user, and the client may implement the same software function in different program forms; for example, the client may be an application APP, an applet, a web browser, or the like. The client in this embodiment has a chat function, the first client and the second client are interactive opposite ends for performing a message chat, the first client may be any client, and the second client may be any client except the first client that performs a chat with the first client. The server may be a background server of the client, for example, the server may be a computer communicatively connected to the client. It should be noted that fig. 1 is only an example provided in this embodiment, a server in this embodiment may simultaneously connect to multiple clients for message distribution, and this embodiment does not make any specific limitation on the number of clients connected to the server.
Referring to fig. 2, fig. 2 is a flowchart illustrating a message processing method according to an embodiment of the present invention, where the method is applied to the above-mentioned system including a first client, a second client and a server, the first client and the second client perform message interaction through the server, and the method is executed on the first client. As shown in fig. 2, the message processing method of this embodiment may include the following steps:
step S11: and sequencing all the messages received in the current time period according to the message ID to generate a new message list.
In this embodiment, a first client receives a message forwarded by a server, and performs batch processing on the received message according to a preset time length, the received message is divided into a message (each message received in a current time period) which needs to be processed currently and a message (each message received in a next time period) which needs to be processed next, for example, the preset time length is 5s, the message with the receiving time of 18:00-18:05 is determined to be received in the current time period, the message with the receiving time of 18:05-18:10 is determined to be received in the next time period, when the message in the next time period is processed, the message with the receiving time of 18:05-18:10 is received in the current time period, the message with the receiving time of 18:10-18:15 is received in the next time period, … … and so on.
The preset time length in this embodiment is an experience time length set in advance, and the experience time length is not too short, so as to avoid frequent calculation of the first client, reduce the calculation pressure of the first client, save calculation resources, and especially when the first client has a large number of messages in a displayed message list (i.e., historical messages), frequent calculation on a poor client device may cause performance problems; the experience time length is not too long, so as to avoid that the chat real-time performance is not good, which causes the experience of the user to be poor, and the embodiment does not make any limitation on the specific value of the preset time length.
In this embodiment, the first client sorts the messages received in the current time period from small to large according to the message IDs to generate a new message list. The message ID refers to a continuously increasing ID assigned by the server to the message received by the server. It can be understood that all messages received by the first client are messages sent to the server by other clients (i.e., the second client), and are forwarded by the server, and when the messages sent by the client are transmitted to the server through the message transmission channel, the server processes the messages, for example, continuously increasing message IDs are allocated to the messages according to the receiving of the messages, the message is marked with the state of the message, the message sending time (e.g., a message timestamp), and the like, and stores the processed messages in a message queue of the server (as shown in fig. 3, which is a message queue diagram shown in fig. 3 according to an embodiment of the present invention), so that the messages in the message queue are sent to the corresponding clients in a first-in first-out manner.
Step S12: intercepting a part of a message list from an already displayed message list to serve as a to-be-processed message list, wherein messages in the already displayed message list are arranged according to the message ID sequence, the arrangement sequence of the messages in the already displayed message list is the same as that of the messages in the new message list, the first message ID in the to-be-processed message list is smaller than the first message ID in the new message list, and the last message ID in the to-be-processed message list is the last message ID in the already displayed message list.
In this embodiment, the first client locally stores a displayed message list, where the displayed message list is a message list composed of messages that have been displayed by the first client, and the messages in the displayed message list are arranged in order from small to large according to the message IDs. The first client intercepts part of the message list from the displayed message list according to the message ID in the new message list to serve as a to-be-processed message list, the to-be-processed message list is the message list which needs to be merged with the new message list at this time, the first message ID in the to-be-processed message list intercepted by the first client is smaller than the first message ID in the new message list, and the last message ID in the to-be-processed message list is the last message ID in the displayed message list. The messages in the displayed message list are arranged according to the message ID sequence, and the arrangement sequence of the messages in the displayed message list is the same as that of the messages in the new message list and is arranged from small to large according to the message IDs, so the messages in the to-be-processed message list intercepted from the displayed message list are also arranged from small to large according to the message IDs. It should be noted that, because the messages in the displayed message list and the messages in the to-be-processed message list are arranged according to the message ID sequence, the first message ID in the two message lists represents the message ID corresponding to the first message in the message list, the last message ID represents the message ID corresponding to the last message in the message list,
the new message list may include real-time new messages and retransmission messages, where a retransmission message is a message that is retransmitted by the server for various reasons, and the retransmission message received by the first client includes: a retransmitted duplicate message, and/or a retransmitted missing compensation message. Because the real-time new message is a subsequent message normally forwarded by the server and is a message after a message forwarded by the server before, that is, the real-time new message is a message after the last message in the displayed message list, if the real-time new message is to be merged with the to-be-processed message list, the to-be-processed message list must include the last message in the displayed message list, and therefore, the last message ID in the to-be-processed message list is the last message ID in the displayed message list; however, because the first message in the new message list may be a retransmission message, and the retransmission message is a message that has been sent to the first client and retransmitted by the server before, the retransmission message should be arranged in the displayed message list after the message with the message ID smaller than the message ID of the retransmission message, so that the size relationship between the first message ID in the message to be processed and the first message ID in the new message list needs to be considered when the retransmission message (which may be the first message in the new message list) is inserted into the message list to be processed, and the retransmission message can be inserted into the message list to be processed only when the first message ID in the message list to be processed is smaller than the first message ID in the new message list. And when the first message ID in the intercepted message list to be processed is smaller than the first message ID in the new message list and the difference value between the first message ID in the message list to be processed and the first message ID in the new message list is minimum, the intercepted message list to be processed can be most reasonable, invalid judgment of the most reasonable message list to be processed is minimum when message IDs are compared subsequently, and computing resources are reduced.
In an optional manner, when the first client intercepts the to-be-processed message list from the displayed message list, a certain number of messages may be sequentially selected from the last message in the displayed message list, until the first message with a message ID smaller than the first message ID in the new message list is selected from the displayed message list. If the first client selects a message from the last message of the displayed message list, and the message ID corresponding to the first message selected to the displayed message list is still not smaller than (i.e. greater than or equal to) the first message ID in the new message list, the displayed message list is directly used as the message list to be processed.
Step S13: comparing the message IDs in the new message list with the message IDs in the pending message list, identifying from the new message list message IDs that are not present in the pending message list, and identifying insertion locations in the pending message list.
In this embodiment, after determining the new message list and the to-be-processed message list, the first client needs to compare the message ID in the new message list with the message ID in the to-be-processed message list, so as to identify the message ID that exists in the new message list but does not exist in the to-be-processed message list, and identify a correct insertion position of the message corresponding to the message ID in the to-be-processed message list, where the to-be-processed message list is inserted according to the correct insertion position, which represents that the to-be-processed message list after the message is inserted does not have a message disorder problem.
Step S14: and inserting the message corresponding to the identified message ID into the insertion position in the message list to be processed to generate a message list to be displayed.
In this embodiment, after the first client identifies the message ID existing in the new message list but not existing in the to-be-processed message list and identifies the correct insertion position of the message corresponding to the message ID in the to-be-processed message list, the first client inserts the message corresponding to the message ID corresponding to the insertion position into the to-be-processed message list according to the identified insertion position, so that the message in the new message list can be inserted into the to-be-processed message list in the correct insertion position according to the message ID, and the two message lists are merged on the premise of avoiding message disorder, thereby generating the to-be-displayed message list.
Step S15: and displaying each message in the message list to be displayed in the next time period.
In this embodiment, after the first client receives a new message in a current time period and generates a message list to be displayed, the messages in the message list to be displayed are sequentially displayed in a next time period, so that the chat messages seen by the user through the client are displayed in a correct order, and the message disorder condition is avoided. For example, the order of the message IDs in the message list to be processed is 2 → 4 → 5, and the order of the message IDs in the new message list is 3 → 6 → 7, then according to the message processing method of the present embodiment, it is recognized that there are no messages in the new message list and the message list to be processed is: message 3, message 6, and message 7; recognizing that the insertion position corresponding to each message is as follows: and after the correct insertion position of the message 3 is between the messages 2 and 4 of the message list to be processed and the correct insertion positions of the message 6 and the message 7 are behind the message 5 of the message list to be processed, inserting the message corresponding to the identified message ID into the message list to be processed according to the correct insertion position, wherein the sequence of the message IDs in the obtained message list to be displayed is 2 → 3 → 4 → 5 → 6 → 7, so that the problem of message disorder is not generated from beginning to end in the real-time chatting process.
When the generated message list to be displayed is sequentially displayed in the next time period, the generated message list to be displayed is simultaneously stored in the local of the client and is used as the displayed message list in the next time period. That is, the messages received in the next time period are sequenced, a new message list is generated, and then the message processing is performed, where the displayed message list to be inserted with the new message is the message list to be displayed generated in the previous time period.
In addition, in this embodiment, when the first client receives a first batch of messages sent by the server (that is, the client receives each message in the initial time period), if the first batch of messages are packaged for the server and sent to the first client at one time, the first batch of messages received by the first client are messages that have been ordered by the server according to the message IDs, the first client receives the first batch of messages and directly displays the first batch of messages, and stores the first batch of messages in the local client as a displayed message list of the next time period; and if the first batch of messages are sent to the first client end one by the server end, the first client end sequences the received first batch of messages according to the message ID and then displays the sequenced first batch of messages, and stores the sequenced first batch of messages locally as a displayed message list of the next time period.
In this embodiment, the messages in the new message list and the messages in the displayed message list are arranged according to the sequence of the message IDs, the to-be-processed message list is extracted from the displayed messages, and the new message list is compared
Determining whether the message ID between the message list and the message to be processed does not exist in the new message list
Message ID in the list and correct insertion position of message corresponding to the message ID in the list of messages to be processed
And inserting the message corresponding to the message ID which does not exist in the message list to be processed into the message list to be processed according to the correct insertion position to generate the message list to be displayed for message display, thereby ensuring that the messages can be displayed in sequence from beginning to end in the real-time chat process.
With reference to the foregoing embodiments, in an implementation manner, an embodiment of the present invention further provides a message processing method. In this method, the step S13 of "comparing the message ID in the new message list with the message ID in the to-be-processed message list, and identifying the message ID not existing in the to-be-processed message list from the new message list" specifically includes steps S21 to S23, the relationship between steps S21 and S23 is shown in fig. 4, and fig. 4 is a flowchart of a message determination method according to an embodiment of the present invention:
step S21: and comparing the first ID with the second ID by taking the compared message ID in the message list to be processed as the first ID and taking the compared message ID in the new message list as the second ID.
In this embodiment, after the first client generates the new message list and the to-be-processed message list, the first client needs to compare the message IDs in the new message list with the message IDs in the to-be-processed message list, and at this time, the message ID to be compared in the to-be-processed message list is the first ID, and the message ID to be compared in the new message list is the second ID, so as to compare the first ID with the second ID.
Step S22: and when the comparison result between the first ID and the second ID represents that the message corresponding to the second ID is a retransmitted loss compensation message, determining that the second ID is the message ID which is not in the message list to be processed.
In this embodiment, after the first client compares the first ID with the second ID, when the comparison result between the first ID and the second ID represents: when the message corresponding to the second ID is the missing compensation message retransmitted by the server, the first client determines that the second ID is a message ID that does not exist in the to-be-processed message list, and needs to insert the message corresponding to the second ID into the to-be-processed message list.
Step S23: and when the comparison result between the first ID and the second ID represents that the message corresponding to the second ID is a new message sent in real time, determining that the second ID is the message ID which does not exist in the message list to be processed.
In this embodiment, after the first client compares the first ID with the second ID, when the comparison result between the first ID and the second ID represents: when the message corresponding to the second ID is a new message sent by the server in real time, the first client determines that the second ID is a message ID that does not exist in the to-be-processed message list, and needs to insert the message corresponding to the second ID into the to-be-processed message list.
In addition, after the first client compares the first ID with the second ID, when the comparison result between the first ID and the second ID characterizes: when the message corresponding to the second ID is a resending message retransmitted by the server, the first client determines that the second ID is a message ID existing in the message list to be processed, and the first client does not need to process the message corresponding to the second ID.
In this embodiment, the first client may identify, according to a comparison result between the first ID and the second ID, whether the message corresponding to the second ID is a retransmitted missing compensation message or a new message transmitted in real time, and when the message corresponding to the second ID is identified as a retransmitted missing compensation message or a new message transmitted in real time, determine the second ID at this time as a message ID that does not exist in the to-be-processed message list, so that when subsequently performing message insertion, only the message corresponding to the second ID that is determined not to exist in the to-be-processed message list may be processed, thereby avoiding insertion of repeated messages in the to-be-processed message list, and further ensuring a chat effect that the messages are sequentially displayed and are not repeated in the real-time chat process.
With reference to the foregoing embodiment, in another implementation manner, an embodiment of the present invention further provides a message processing method. In the method, a message ID comparison method is also provided, which specifically includes steps S31 to S33. The relationship between steps S31 and S33 is shown in fig. 5, and fig. 5 is a flowchart illustrating a message comparison method according to an embodiment of the present invention.
Step S31: and when the comparison is carried out for the first time, determining the first message ID in the message list to be processed as the first ID, and determining the first message ID in the new message list as the second ID.
In this embodiment, when performing the first message ID comparison, the first message ID in the to-be-processed message list is used as the first ID (that is, the first ID is a message ID corresponding to the first message in the to-be-processed message list), and the first message ID in the new message list is used as the second ID (that is, the second ID is a message ID corresponding to the first message in the new message list), so as to perform the message ID size comparison between the first ID and the second ID.
In an alternative embodiment, in order to clarify the specific positions of the two messages in the respective lists at each message comparison, the comparison between the message IDs may be performed by setting a pointer: for example, a first pointer may be set for the message list to be processed, a second pointer may be set for the new message list, and the initial positions of the first pointer and the second pointer both point to the first message in the message list, that is, when the first message ID comparison is performed, the first pointer points to the first message in the message list to be processed, and the second pointer points to the first message in the new message list, so as to perform the comparison between the message ID pointed by the first pointer and the message ID pointed by the second pointer.
Step S32: when the comparison result between the first ID and the second ID is: and when the first ID is smaller than the second ID, taking the second ID as a second ID in next comparison, traversing the message list to be processed from the first ID downwards until the message ID which is larger than or equal to the second ID in the message list to be processed is found, and taking the message ID as a first ID in next comparison.
In this embodiment, when the first client performs the comparison between the first ID and the second ID, and the comparison result between the first ID and the second ID is: when the first ID is smaller than the second ID, it is determined that the second ID should be behind the first ID, but the specific position of the second ID compared with the first ID cannot be determined (e.g., it cannot be determined whether the current second ID is one, two, or three bits after the current first ID), so that the second ID is used as the second ID for the next comparison to continue the comparison. For the first ID, the message list to be processed needs to be traversed from the current first ID downward until a message ID greater than or equal to the current second ID in the message list to be processed is found, and the found message ID is used as the first ID for the next comparison, so as to perform the subsequent message comparison.
For example, if the first ID is 2 and the second ID is 5, the message IDs in the message list to be processed are 2 → 3 → 4 → 6 in order, the first ID is compared with the second ID, and the first ID2 is determined to be smaller than the second ID5, then the second ID5 is determined to be the second ID in the next comparison, i.e., the second ID is not changed and still is 5 in the next comparison; and for the first ID, it goes from 2 down until a message ID greater than or equal to the second ID5 is found from the pending message list, at which point it is determined 6 to be the first ID at the next comparison.
In an optional implementation manner, the comparison between the message IDs may be performed by setting pointers, and continuing to take the first pointer and the second pointer as an example: and comparing the size relationship between the message ID pointed by the first pointer and the message ID pointed by the second pointer, wherein when the message ID pointed by the first pointer is smaller than the message ID pointed by the second pointer, the position of the second pointer is unchanged, and the first pointer moves downwards until the message ID pointed by the first pointer is larger than or equal to the message ID pointed by the second pointer, so that the comparison is completed.
Step S33: when the comparison result between the first ID and the second ID is: and when the first ID is larger than or equal to the second ID, taking the next message ID of the second ID as the second ID in the next comparison, and taking the first ID as the first ID in the next comparison.
In this embodiment, when the first client performs the comparison between the first ID and the second ID, and the comparison result between the first ID and the second ID is: when the first ID is equal to the second ID, it may be determined that the second ID already exists in the to-be-processed message list, where the message corresponding to the second ID is already shown in the to-be-processed message list, and the message corresponding to the second ID is a repeated message retransmitted by the server. Thus, for new message lists
The repeated message (i.e. the message corresponding to the second ID) in (1) is not processed, and the next message of the second ID is processed
The IDs are subsequently compared as the second ID in the next comparison, while for the first ID, the first ID is unchanged and the comparison continues with the first ID as the first ID in the next comparison.
For example, if the first ID is 5 and the second ID is 5, the message IDs in the new message list are 5 → 6 → 7 in order, the first ID is compared with the second ID, and the first ID5 is determined to be equal to the second ID5, then the first ID5 is determined to be the first ID in the next comparison, i.e., the first ID is not changed in the next comparison and still is 5; and for the second ID, the next message ID to the second ID is found, i.e., the next message ID6 after message ID5 is found, and then message ID6 is determined to be the second ID for the next comparison, thereby completing the comparison of the message IDs.
In an optional implementation manner, the comparison between the message IDs may be performed by setting pointers, and continuing to take the first pointer and the second pointer as an example: and comparing the size relationship between the message ID pointed by the first pointer and the message ID pointed by the second pointer, wherein when the message ID pointed by the first pointer is equal to the message ID pointed by the second pointer, the position of the first pointer is unchanged, and the second pointer is moved downwards by one bit, so that the comparison is completed.
In this embodiment, when the first client performs the comparison between the first ID and the second ID, and the comparison result between the first ID and the second ID is: and when the first ID is larger than the second ID, determining that the second ID does not exist in the message list to be processed, and the second ID is before the first ID, wherein the message corresponding to the second ID is a missing compensation message retransmitted by the server side in the message list to be processed. Thus, the next message ID to this second ID is now taken as the second ID in the next comparison for subsequent comparisons; for the first ID, the first ID is not changed, that is, the first ID is used as the first ID in the next comparison to continue the comparison, thereby completing the current message ID comparison.
For example, if the first ID is 6 and the second ID is 5, the message IDs in the pending message list are 6 → 7 → 8 in sequence, and the message IDs in the new message list are 5 → 7 in sequence, comparing the first ID with the second ID, determining that the first ID6 is greater than the second ID5, then determining that the first ID6 is the first ID in the next comparison, i.e., the first ID is unchanged and still is 6 in the next comparison; and for the second ID, the next message ID to the second ID is found, i.e., the next message ID7 after message ID5 is found, and then message ID7 is determined to be the second ID for the next comparison, thereby completing the comparison of the message IDs.
In an optional implementation manner, the comparison between the message IDs may be performed by setting pointers, and continuing to take the first pointer and the second pointer as an example: and comparing the size relationship between the message ID pointed by the first pointer and the message ID pointed by the second pointer, and when the message ID pointed by the first pointer is larger than the message ID pointed by the second pointer, keeping the position of the first pointer unchanged, and moving the second pointer downwards by one bit, thereby finishing the comparison.
When the message IDs of the new message list and the message list to be processed are compared, the comparison method provided by the embodiment gradually compares the first ID with the second ID, so that the condition of each message in the new message list can be sequentially determined, and the first ID in the message list to be processed in the next comparison and the second ID in the new message list in the next comparison are determined according to the condition to perform subsequent comparison, so that each message in the new message list can be accurately processed in the comparison process, and the sequential display of the messages is ensured.
In combination with the above embodiment, in an implementation manner, the insertion positions in the message list to be processed include a first insertion position and a second insertion position, and the determination of the first insertion position and the second insertion position needs to be determined according to a comparison condition between the first ID and the second ID: wherein the content of the first and second substances,
for the first insertion position: when the comparison result between the first ID and the second ID represents that the message corresponding to the second ID is a retransmitted loss compensation message, determining that a first insertion position is: the first ID corresponds to a previous bit of the message.
In this embodiment, when the first client performs comparison between the first ID and the second ID, and a comparison result between the first ID and the second ID indicates that the message corresponding to the second ID is a retransmitted missing compensation message, it indicates that the second ID is smaller than the first ID, and the second ID is in front of the first ID, so that the first client determines that the first insertion position in the to-be-processed message list is: the first ID corresponds to a bit preceding the message.
For the second insertion position: when each message in the message list to be processed participates in comparison so that the comparison is finished, or when the comparison result between the first ID and the second ID represents that the message corresponding to the second ID is a new message sent in real time, determining a second insertion position as follows: and the end of the message list to be processed.
In this embodiment, each message in the to-be-processed message list is already involved in the comparison, so that the comparison of the message IDs is completed, where the first ID is the last message ID in the to-be-processed message list, and the first ID is already compared with the second ID, and the comparison of the message IDs is completed if there is no remaining message in the to-be-processed message list that can be subsequently compared with the message in the new message list.
For example: the message IDs in the pending messages are 5 → 7 → 9 in the order, and the message IDs in the new message list are 6 → 10 → 11 → 12 in the order, when the first ID is 9, the previous message ID5, message ID7 have been compared, and when the first ID9 is compared to the second ID10, the first ID9 is less than the second ID10, when the comparison of the message IDs ends because no message behind the first ID9 greater than or equal to the second ID10 can be found for subsequent comparison.
At this time, if there are remaining messages not inserted in the pending message list in the new message list, it should be inserted at the end of the pending message list, so that the first client determines that the second insertion position in the pending message list is: the end of the pending message list.
In this embodiment, if the first client performs comparison between the first ID and the second ID, and a comparison result between the first ID and the second ID indicates that the message corresponding to the second ID is a new message sent in real time, it indicates that the message corresponding to the second ID is a subsequent message of the message in the message list to be processed of the first client, and therefore, the first client determines that the second insertion position in the message list to be processed is: the end of the pending message list.
In this embodiment, according to the comparison condition of the message IDs between the two message lists, a reasonable insertion position of the message corresponding to each second ID with respect to the message list to be processed can be determined, and further, a guarantee is provided for performing message sequence display while compensating and updating the messages in the message list to be processed in the subsequent process.
With reference to the foregoing embodiment, in an implementation manner, the first client further needs to insert the identified message corresponding to the message ID according to a comparison between the first ID and the second ID, where the message insertion in this embodiment is divided into the following two cases:
in the first case: during the comparison, inserting the identified loss compensation message into the first insertion location in the pending message list.
In this embodiment, in the process of comparing the first ID in the message list to be processed with the second ID in the new message list, the first client determines that the message corresponding to the second ID is the missing compensation message, and after the insertion position corresponding to the second ID is the first insertion position, the first client may insert the message corresponding to the second ID (i.e., the identified missing compensation message) into the message list to be processed according to the determined first insertion position (i.e., the previous position of the message corresponding to the first ID currently being compared).
Further, it should be noted that: each message in the new message list is already involved in the comparison, so that the message ID ends the comparison, at this time, it is: the second ID currently being compared is the message ID of the last message in the new message list, and the last message in the new message list has already completed message processing (i.e., the message corresponding to the second ID has already been inserted into the to-be-processed list or the message corresponding to the second ID is determined to be a duplicate message, and does not need to process the message), and if no message in the new message list needs to be processed, the comparison of the message IDs is ended.
For example: the message IDs in the new message list are 3 → 6 → 8 in sequence, at this time, the second ID is 8, the previous message ID3 and the message ID6 have been compared, the second ID8 has been compared with the first ID, and the message corresponding to the second ID8 has been inserted into the message list to be processed or the message corresponding to the second ID8 is determined to be a duplicate message without processing, and the message corresponding to the second ID8 has no message following, which represents that the message processing in the new message list has been completed, then the comparison of the message IDs is ended.
It can be seen that, in this case, the comparison of the message IDs is finished, and the messages in the new message list have completed message processing in the comparison process (the messages are all inserted according to the first insertion position or the messages are duplicate messages and do not need to be processed), which also belongs to the first case mentioned above, and in the comparison process, the identified missing compensation message is inserted into the first insertion position in the message list to be processed.
In the second case: and under the condition that all the messages in the message list to be processed participate in comparison so that the comparison is finished and the messages after the message corresponding to the second ID are not yet participated in the comparison, inserting the message corresponding to the second ID and the messages after the message corresponding to the second ID into the second insertion position in the message list to be processed.
In this embodiment, the first client determines that the first ID is the last message ID in the to-be-processed message list, and the first ID has been compared with the second ID, and when the message corresponding to the second ID and the messages after the second ID are not yet inserted into the to-be-processed list, the message corresponding to the second ID and the messages after the second ID are represented as real-time new messages received by the first client at this time, and the first client inserts the message corresponding to the second ID in the new message list and the messages after the message corresponding to the second ID into the second insertion position (i.e., the end of the to-be-processed message list) in the to-be-processed message list to complete message update of the to-be-processed message list.
The first client may sequentially insert the message corresponding to the second ID and the message after the message corresponding to the second ID into the end of the to-be-processed message list according to the sequence of the message IDs, or may insert the message corresponding to the second ID and the message after the message corresponding to the second ID into the end of the to-be-processed message list together, which is not limited in this embodiment.
In addition, when the message insertion is specifically performed, the first client may copy the message corresponding to the second ID from the new message list, and insert the copied message corresponding to the second ID into the message list to be processed according to the determined insertion position (the first insertion position or the second insertion position), so that the message corresponding to the second ID in the new message list is not removed or deleted, and the problem of message disorder caused by message removal in the new message list can be avoided; alternatively, the first client may list the new message directly
The message corresponding to the second ID in the message list is moved to the insertion position in the message list to be processed, and the new message list
The message corresponding to the second ID of (2) is removed, and the embodiment does not make any specific limitation on the two methods for inserting the message.
In this embodiment, the first client inserts the message in the new message list into the to-be-processed message list according to the comparison condition of the message IDs and the determined insertion position, so that the real-time message and/or the missing compensation message included in the new message list can be merged and displayed with the to-be-processed message list at a correct position, and the messages in the to-be-processed message list are compensated and updated while the sequential display of the messages is ensured. The method not only can quickly complete message insertion and combination, but also only affects limited local chat messages (namely only affects the message list to be processed) in the combination process, the re-rendering of the whole message list (all displayed messages) can not occur, and the user experience is improved.
In combination with the above embodiment, in an implementation manner, the present invention further provides a message processing method, in which step S15 is followed by step S41 to step S43. The relationship between steps S41 and S43 is shown in fig. 6, and fig. 6 is a flowchart illustrating a message compensation method according to an embodiment of the present invention.
Step S41: and traversing the message list to be displayed and judging whether the message IDs in the message list to be displayed are continuous or not.
In this embodiment, after the first client generates the message list to be displayed, the first client may also traverse the message list to be displayed, and determine whether the message IDs in the message list to be displayed are consecutive.
Step S42: when the message ID in the message list to be displayed is discontinuous or when foreground and background switching occurs in response to a chat interface, pulling a compensation message of a first time period from an offline database; and all messages which need to be sent to the first client side are backed up in the offline database.
In this embodiment, when the first client determines that the message ID in the message list to be displayed is discontinuous, that is, it represents that there is still a missing message in the message list to be displayed, the first client may actively request the offline database for the compensation message of the first time period. In the process of forwarding messages between clients, when a message is sent to a server by a client, the server processes the received message (as described above, continuously increasing message IDs are allocated to the message, the message is marked for the state, the message sending time, and the like), and then stores the processed message in an offline database for backup. That is, all messages that need to be sent to the client are backed up in the offline database.
In this embodiment, the first client pulls the compensation message of the first time period to the offline database, where the first client sends a compensation message request to the offline database, where the request carries the first time period information and the identifiers of both message receivers, and the offline database responds to the compensation message request after receiving the compensation message request, and returns the backup message of the first time period to the first client according to the compensation message request, that is, the compensation message is a specified backup message that is actively pulled from the offline database by the first client and is arranged in the sequence of the message IDs.
In this embodiment, when the client is switched back to the background from the chat interface or the client is switched into the chat interface from the background, the code may not be executed and the message may not be normally received, so that when the first client performs foreground and background switching in response to the chat interface, that is, when the first client detects that the client is switched out from the chat interface to another interface or switched into the chat interface from another interface, the first client may actively pull the compensation message of the first time period to the offline database to perform compensation for displaying the message.
Step S43: and performing message offline compensation on the message list to be displayed according to the compensation message.
In this embodiment, after receiving the compensation message returned by the offline database, the first client may perform offline message compensation on the to-be-displayed message list according to the compensation message. When the message offline compensation is performed, the compensation message is regarded as the new message list, the message list to be displayed is regarded as the message list to be processed, and the compensation message and the message list to be displayed are merged by the message merging method of the foregoing embodiments, so as to generate a new message list to be displayed.
The difference between the message offline compensation and the message merging processing method of the new message list and the message list to be processed is only that: the compensation message is a message actively pulled by the first client to the offline database, and the messages in the new message list are messages forwarded by the server passively received by the first client.
In this embodiment, by setting a reasonable offline compensation mechanism, when the first client detects that the messages after the message combination processing are still discontinuous or detects that the chat interface is switched between the foreground and the background, offline compensation is triggered, and the message list in the offline database is pulled to be further combined with the display messages, so that offline compensation of the display messages of the first client is realized, and it is ensured that the user can still reliably receive the lost messages in the scene of network failure in a short time or in the application cut-out process of the chat process.
In combination with the above embodiments, in one implementation, when performing offline message compensation, the first time period may be determined in the following three ways:
the first mode is as follows: when the message offline compensation is the first message offline compensation and the message offline compensation is the message offline compensation performed when the message ID in the message list to be displayed is discontinuous, the first time period is a time interval in which the receiving time of the second message is used as the starting time and the current time is used as the ending time; and the second message is the previous message of the missing message in the message list to be displayed.
In this embodiment, when the message offline compensation is the first message offline compensation, and the message offline compensation is performed when the first client determines that the message ID in the message list to be displayed is discontinuous, the first client actively pulls the compensation message of a first time period to the offline database, where the first time period is: and the time interval takes the receiving time of the second message as the starting time and takes the current time as the ending time. For example, after the first client traverses the message list to be presented, it is determined that the message IDs in the message list to be presented are discontinuous, where the discontinuous message ID is 6 → 8, and at this time, it is determined that there is a missing message between the message corresponding to the message ID6 and the message corresponding to the message ID8, and then the previous message (i.e., the message corresponding to the message ID 6) of the missing message is the second message.
In this embodiment, when determining the first offline compensation triggered when the message ID of the message list to be presented is discontinuous, it may be determined that a message is lost in the middle of the message list, but it cannot be determined whether the last message is lost, so for the sake of insurance, the compensation message pulled by the first client to the offline database is a received message pulled backward to the current time from the time when the received time of the previous message of the missing message in the message list to be presented is the starting time, and thus it can be ensured that the missing message is compensated sufficiently.
The second way is: and when the message offline compensation is the first message offline compensation and the message offline compensation is performed when the chat interface is switched between the foreground and the background, the first time period is a time interval in which the receiving time of the last message in the message list to be displayed is used as the starting time and the current time is used as the ending time.
In this embodiment, when the offline message compensation is the first offline message compensation, and the offline message compensation is performed when the first client performs the foreground and background switching in response to the chat interface, the first client actively pulls the compensation message of the first time period to the offline database, where the first time period is: and taking the receiving time of the last message in the message list to be displayed as the starting time and taking the current time as the time interval of the ending time.
In this embodiment, when responding to the first offline compensation triggered when the chat interface is switched between the front and the back, a new message may be lost, and therefore the end time of pulling the compensation message needs to be the current time, that is, at this time, the compensation message pulled from the offline database by the first client is a received message that is continuously pulled backward to the current time from the time of receiving the last message in the message list to be displayed as the start time, so that the current chat interface can be refreshed, and whether an updated message after the message is displayed last time exists is automatically compensated.
The third mode is as follows: when the message offline compensation is the subsequent message offline compensation, and the first time period is the previous message offline compensation, the receiving time of the last message in the compensation messages is used as the starting time, and the current time is used as the time interval of the ending time.
In this embodiment, when the offline compensation of the message is the offline compensation of the subsequent message, regardless of whether the offline compensation is the offline compensation triggered when the first client detects that the message ID in the message list to be displayed is discontinuous or the offline compensation triggered when the first client responds to the chat interface and performs the foreground and background switching, the first client actively pulls the compensation message of the first time period to the offline database, where the first time period is: the receiving time of the last message in the compensation message of the previous message off-line compensation is used as the starting time, and the current time is used as the time interval of the ending time.
In this embodiment, when the first client triggers the subsequent offline compensation after the first offline compensation, the compensation message pulled from the offline database by the first client is the received message that is pulled to the current time from the received time of the last message in the compensation message pulled from the previous offline compensation as the start time, and is continuously pulled backward, so that the compensation of the displayed message by the subsequent message of the previous compensation message can be realized.
In this embodiment, the compensation messages in different time intervals are pulled according to the offline compensation conditions, so that accurate pulling of the compensation messages is realized, accurate offline compensation of the messages displayed by the first client is ensured, and the experience of the user in receiving the chat messages is further improved.
With reference to the foregoing embodiment, in an implementation manner, the present invention further provides a message processing method, and specifically, the method further includes: in the process of transmitting the message through a transmission channel between the client and the server, detecting the transmission channel in a parallel mode through a first detection method and a second detection method to detect whether the transmission channel is inactivated or disconnected, and reconnecting when the transmission channel is inactivated or disconnected.
In this embodiment, a message is transmitted through a transmission channel between a client (e.g., a first client or a second client) and a server, and if the transmission channel may be disconnected or inactivated due to various reasons (e.g., network reasons, device reasons, etc.), in order to ensure reliable transmission of the message, the embodiment further performs detection of the transmission channel during message processing: in the process of transmitting the message through the transmission channel between the client and the server, the transmission channel can be detected in a parallel mode through two methods (a first detection method and a second detection method) so as to detect whether the transmission channel between the client and the server is inactivated or disconnected, and when the transmission channel is inactivated or disconnected, the transmission channel is reconnected.
The first detection method comprises the following steps: and the plug-in used for opening the webpage in the first client monitors the transmission channel so as to monitor whether the transmission channel is inactivated or disconnected.
In this embodiment, a plug-in for opening a web page in a first client may be Webview or the like, the plug-in for opening a web page in the first client has a monitoring function, when a network environment where the first client or a server is located has great uncertainty and fluctuation is large, a network of the first client may be disconnected, and if the network disconnection time is long, the plug-in can monitor that a transmission channel is disconnected, the plug-in notifies the first client of a reconnection attempt; if the network disconnection time is short or the server message distribution is blocked, the plug-in usually cannot sense whether the channel is disconnected, so that other checking methods are required to perform channel detection at the same time. In an optional manner, when the plug-in monitors that the transmission channel is disconnected, the plug-in may also directly perform public network access to determine whether the network failure is a network failure of the first client side, and if the network failure is a network failure of the first client side, prompt the user to reconnect the network to reconnect the transmission channel.
The second detection method comprises the following steps: and when the first client side cannot receive the detection message repeatedly sent to the first client side by the server side at a fixed time interval within a first time length, determining that the transmission channel is inactivated or disconnected.
In this embodiment, the server may also repeatedly send a ping message (heartbeat detection) to the first client at fixed time intervals, and if the first client receives the ping message, the server may reply a pong message; and when the first client does not receive the ping message within the first time length, determining that the transmission channel is inactivated or disconnected, and thus reconnecting the transmission channel. The first duration is a preset time period in the heartbeat detection process, a channel is considered to be normal if a ping message is received in the time period, and the channel is considered to be inactivated or disconnected if the ping message is not received in the time period.
In the embodiment, the state of the transmission channel is detected in a parallel mode by two methods in the message transmission process, so that the real-time detection and the timely connection retry of the network condition and the stability of the transmission channel are realized, and the user experience in the message receiving and sending process is further improved.
With reference to the foregoing embodiment, in an implementation manner, the present invention further provides a message processing method, where a transmission channel is a WS channel, and the method further includes: and when the WS channel exceeds a second duration and is still not successfully connected, establishing a transmission channel between the first client and the server through an HTTP protocol.
In this embodiment, a chat scene between users is a web chat scene, a client performs sending, receiving and displaying of messages through a web page, a message transmission channel between the client and a server is a WS channel, that is, a websocket channel, and the websocket channel has the characteristics of low delay and permanently reusable channels, and is widely used in real-time chat scenes of users.
When the first client detects that the websocket channel is still not successfully connected for a long time, that is, when the first client detects that the websocket channel still does not successfully connect for a longer time than a second time length (where the second time length is a preset maximum time length for allowing the channel to be disconnected, and a specific value of the second time length is not specifically limited in this embodiment), the channel connection between the first client and the server is established through an HTTP protocol, so that degradation of the message transmission channel is achieved, and reliable transmission of the message can be effectively ensured.
It should be noted that the degradation of the message transmission channel does not affect the message processing method proposed in the present application, because the message transmission is changed from the websocket protocol to the HTTP protocol, the difference is only whether the client actively requests whether there is a new message, and after the message is transmitted to the client (i.e. after the client receives the message), the method for the client to process the message is not changed.
In this embodiment, when the websocket channel has a long-term failure, reliable transmission of the message can still be effectively ensured through degradation processing of the transmission protocol, so that a basic guarantee is provided for messaging in a real-time chat scene.
In an implementation manner, in combination with the above embodiment, the present invention further provides a message processing method, specifically, the method further includes step S51 and step S52, a relationship between step S51 and step S52 is shown in fig. 7, and fig. 7 is a flowchart of a message delivery confirmation method according to an embodiment of the present invention.
Step S51: and in the process of transmitting the message through a transmission channel between the first client and the server, the delivery confirmation of the message is carried out through an ACK mechanism.
In this embodiment, since the message transmission may reach the server first and then be forwarded by the server, and there is a possibility of message loss in each transmission link, in the process of transmitting the message through the transmission channel between the client and the server, the delivery acknowledgement of the message is performed through an ACK mechanism: the message carries an ACK message in the transmission process, and when the receiver receives the message, the receiver returns an ACK response message to the sender to represent the successful delivery of the message.
Step S52: and when the ACK response of the server is not received in the third time length, retransmitting the message.
In this embodiment, when the first client does not receive the ACK response returned by the server within the third duration, the first client determines that the server does not receive the message sent by the first client, and if the sending of the message fails, the first client may resend the message to the server at an appropriate time, so as to implement resending of the message. Wherein, the suitable time can be: after the transmission channel is reconnected successfully or after the current message is sent out (i.e. on the premise of not interfering the current message). And if the server side does not receive the ACK response returned by the first client side within the third duration, the server side determines that the first client side does not receive the message sent by the server side, and if the message is failed to be sent, the server side resends the message to the first client side, so that the message is resent. The third duration is a maximum duration which is preset in this embodiment and is considered to be successful in message transmission, an ACK response received exceeding the third duration is also considered to be failed in message transmission, and this embodiment does not make any specific limitation on a specific value of the third duration.
In this embodiment, in the transmission process of the message, the delivery acknowledgement of the message is performed through an ACK mechanism to determine the time for retransmitting the message in real time, so that a scene of message transmission failure can be processed in time, which provides a basic guarantee for the real-time receiving and sending of the message in a real-time chat scene.
With reference to the foregoing embodiment, in an implementation manner, in a process of performing real-time chat by two clients, a messaging process is as shown in fig. 8, and fig. 8 is a schematic message interaction diagram according to an embodiment of the present invention. The first client and the second client carry out message interaction through the server, and the server can carry out message processing on the received messages and store the processed messages into a message queue. Wherein, the messages carry an ACK message in the transmission process, the receiver needs to respond to the ACK, and when the sender does not receive the ACK response within a period of time (such as the third duration), the sender retransmits the messages. Moreover, the server side can repeatedly send ping messages to the clients (the first client side and the second client side) at fixed time intervals, and if the first client side or the second client side receives the ping messages, the ping messages can be replied to the server side; and when the first client or the second client does not receive the ping message within the first time length, determining that the transmission channel between the client and the server is inactivated or disconnected, and reconnecting the transmission channel.
It should be noted that, for simplicity of description, the method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present invention is not limited by the illustrated order of acts, as some steps may occur in other orders or concurrently in accordance with the embodiments of the present invention. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no particular act is required to implement the invention.
Based on the same inventive concept, an embodiment of the present invention provides a message processing apparatus 900, where the apparatus 900 is applied to a system including a first client, a second client, and a server, where the first client and the second client perform message interaction through the server, and the apparatus is disposed at the first client. Referring to fig. 9, fig. 9 is a block diagram of a message processing apparatus according to an embodiment of the present invention. As shown in fig. 9, the apparatus 900 includes:
a generating module 901, configured to sort, according to the message ID, each message received in the current time period, and generate a new message list;
an intercepting module 902, configured to intercept a partial message list from an already displayed message list as a to-be-processed message list, where messages in the already displayed message list are arranged according to the message ID sequence, the arrangement sequence of the messages in the already displayed message list is the same as the arrangement sequence of the messages in the new message list, a first message ID in the to-be-processed message list is smaller than a first message ID in the new message list, and a last message ID in the to-be-processed message list is a last message ID in the already displayed message list;
a comparing module 903, configured to compare the message ID in the new message list with the message ID in the to-be-processed message list, identify, from the new message list, a message ID that is not present in the to-be-processed message list, and identify an insertion position in the to-be-processed message list;
an inserting module 904, configured to insert the identified message corresponding to the message ID into the insertion position in the to-be-processed message list, so as to generate a to-be-displayed message list;
a displaying module 905, configured to display each message in the message list to be displayed in a next time period.
Optionally, the comparing module 903 includes:
the comparison submodule is used for comparing the first ID with the second ID by taking the compared message ID in the message list to be processed as the first ID and taking the compared message ID in the new message list as the second ID;
a first message determining module, configured to determine that the second ID is the message ID that is not present in the to-be-processed message list when a comparison result between the first ID and the second ID indicates that the message corresponding to the second ID is a retransmitted loss compensation message;
a second message determining module, configured to determine that the second ID is the message ID that is not present in the to-be-processed message list when a comparison result between the first ID and the second ID indicates that the message corresponding to the second ID is a new message sent in real time.
Optionally, the comparing module 903 further includes:
a first insertion location determining module, configured to determine, when a comparison result between the first ID and the second ID indicates that the message corresponding to the second ID is a retransmitted loss compensation message, that a first insertion location is: a previous bit of a message corresponding to the first ID;
a second insertion position determining module, configured to determine, when each message in the to-be-processed message list participates in comparison so that the comparison is completed, or when a comparison result between the first ID and the second ID indicates that a message corresponding to the second ID is a new message sent in real time, that a second insertion position is: and the end of the message list to be processed.
Optionally, the inserting module 904 includes:
a first insertion sub-module, configured to insert the identified missing compensation message into the first insertion position in the to-be-processed message list during the comparison process;
and a second inserting sub-module, configured to insert the message corresponding to the second ID and the message after the message corresponding to the second ID into the second inserting position in the to-be-processed message list when each message in the to-be-processed message list participates in the comparison, so that the comparison is completed, and the message after the message corresponding to the second ID does not participate in the comparison yet.
Optionally, the apparatus 900 further includes:
a first comparison sub-module, configured to determine, during first comparison, a first message ID in the to-be-processed message list as the first ID, and determine a first message ID in the new message list as the second ID;
a first message ID determination module, configured to, when the comparison result between the first ID and the second ID is: when the first ID is smaller than the second ID, taking the second ID as a second ID in next comparison, traversing the message list to be processed from the first ID downwards until a message ID which is larger than or equal to the second ID in the message list to be processed is found, and taking the message ID as a first ID in next comparison;
a second message ID determination module, configured to, when the comparison result between the first ID and the second ID is: and when the first ID is larger than or equal to the second ID, taking the next message ID of the second ID as the second ID in the next comparison, and taking the first ID as the first ID in the next comparison.
Optionally, the apparatus 900 further includes:
the traversal module is used for traversing the message list to be displayed and judging whether the message IDs in the message list to be displayed are continuous or not;
the message pulling module is used for pulling the compensation message of the first time period to the offline database when the message ID in the message list to be displayed is discontinuous or when the foreground and background switching is generated in response to the chat interface; all messages needing to be sent to the first client side are backed up in the offline database;
and the offline compensation module is used for performing message offline compensation on the message list to be displayed according to the compensation message.
Optionally, the first time period is:
when the message offline compensation is the first message offline compensation and the message offline compensation is the message offline compensation performed when the message ID in the message list to be displayed is discontinuous, the first time period is a time interval in which the receiving time of the second message is used as the starting time and the current time is used as the ending time; the second message is the previous message of the missing message in the message list to be displayed; alternatively, the first and second electrodes may be,
when the message offline compensation is the first message offline compensation and the message offline compensation is performed when the chat interface is switched between the foreground and the background, the first time period is a time interval in which the receiving time of the last message in the message list to be displayed is used as the starting time and the current time is used as the ending time; alternatively, the first and second electrodes may be,
when the message offline compensation is the subsequent message offline compensation, and the first time period is the previous message offline compensation, the receiving time of the last message in the compensation messages is used as the starting time, and the current time is used as the time interval of the ending time.
Optionally, the apparatus 900 further includes:
the detection module is used for detecting the transmission channel in a parallel mode by a first detection method and a second detection method in the process of transmitting the message through the transmission channel between the first client and the server so as to detect whether the transmission channel is inactivated or disconnected, and reconnecting the transmission channel when the transmission channel is inactivated or disconnected;
the first detection method comprises the following steps: a plug-in used for opening a webpage in the first client monitors the transmission channel to monitor whether the transmission channel is inactivated or disconnected;
the second detection method comprises the following steps: and when the first client side cannot receive the detection message repeatedly sent to the first client side by the server side at a fixed time interval within a first time length, determining that the transmission channel is inactivated or disconnected.
Optionally, the transmission channel is a WS channel, and the apparatus 900 further includes:
and the downgrade module is used for establishing a transmission channel between the first client and the server through an HTTP protocol when the WS channel is not successfully connected after exceeding the second time length.
Optionally, the apparatus 900 further includes:
the ACK mechanism module is used for confirming the delivery of the message through an ACK mechanism in the process of transmitting the message through a transmission channel between the first client and the server;
and the retransmission module is used for retransmitting the message when the ACK response of the server is not received in the third time length.
Based on the same inventive concept, another embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the steps in the message processing method according to any one of the above-mentioned embodiments of the present invention.
Based on the same inventive concept, another embodiment of the present invention provides an electronic device 1000, as shown in fig. 10. Fig. 10 is a schematic diagram of an electronic device according to an embodiment of the present invention. The electronic device comprises a memory 1002, a processor 1001 and a computer program stored on the memory and executable on the processor, which when executed implements the steps in the message processing method according to any of the above embodiments of the present invention.
For the device embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus, or computer program product. Accordingly, embodiments of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
Embodiments of the present invention are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing terminal to cause a series of operational steps to be performed on the computer or other programmable terminal to produce a computer implemented process such that the instructions which execute on the computer or other programmable terminal provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the embodiments of the invention.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or terminal that comprises the element.
The above detailed description is given of a message processing method, a message processing apparatus, an electronic device, and a readable storage medium, and a specific example is applied in the present disclosure to explain the principle and the implementation of the present invention, and the description of the above embodiment is only used to help understanding the method and the core idea of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.

Claims (13)

1. A message processing method is applied to a system comprising a first client, a second client and a server, wherein the first client and the second client perform message interaction through the server, and the method is executed on the first client, and the method comprises the following steps:
sequencing all messages received in the current time period according to the message ID to generate a new message list;
intercepting a part of message list from an already displayed message list to serve as a to-be-processed message list, wherein messages in the already displayed message list are arranged according to the message ID sequence, the arrangement sequence of the messages in the already displayed message list is the same as that of the messages in the new message list, the first message ID in the to-be-processed message list is smaller than the first message ID in the new message list, and the last message ID in the to-be-processed message list is the last message ID in the already displayed message list;
comparing the message IDs in the new message list with the message IDs in the to-be-processed message list, identifying from the new message list the message IDs that are not present in the to-be-processed message list, and identifying an insertion position in the to-be-processed message list;
inserting the message corresponding to the identified message ID into the insertion position in the message list to be processed, and generating a message list to be displayed;
and displaying each message in the message list to be displayed in the next time period.
2. The method of claim 1, wherein comparing the message IDs in the new message list to the message IDs in the pending message list identifies message IDs from the new message list that are not present in the pending message list, comprises:
comparing the first ID with the second ID by taking the compared message ID in the message list to be processed as the first ID and taking the compared message ID in the new message list as the second ID;
when the comparison result between the first ID and the second ID represents that the message corresponding to the second ID is a retransmitted loss compensation message, determining that the second ID is the message ID which does not exist in the message list to be processed;
and when the comparison result between the first ID and the second ID represents that the message corresponding to the second ID is a new message sent in real time, determining that the second ID is the message ID which does not exist in the message list to be processed.
3. The method of claim 2, wherein comparing the message IDs in the new message list to the message IDs in the pending message list identifies an insertion location in the pending message list, comprising:
when the comparison result between the first ID and the second ID represents that the message corresponding to the second ID is a retransmitted loss compensation message, determining that a first insertion position is: a previous bit of a message corresponding to the first ID;
when each message in the message list to be processed participates in comparison so that the comparison is finished, or when the comparison result between the first ID and the second ID represents that the message corresponding to the second ID is a new message sent in real time, determining a second insertion position as follows: and the end of the message list to be processed.
4. The method according to claim 3, wherein the inserting the message corresponding to the identified message ID into the inserting position in the message list to be processed generates a message list to be presented, comprising:
during the comparison, inserting the identified loss compensation message into the first insertion position in the message list to be processed;
and under the condition that all the messages in the message list to be processed participate in comparison so that the comparison is finished and the messages after the message corresponding to the second ID are not yet participated in the comparison, inserting the message corresponding to the second ID and the messages after the message corresponding to the second ID into the second insertion position in the message list to be processed.
5. The method of claim 2, further comprising:
when the comparison is carried out for the first time, determining the first message ID in the message list to be processed as the first ID, and determining the first message ID in the new message list as the second ID;
when the comparison result between the first ID and the second ID is: when the first ID is smaller than the second ID, taking the second ID as a second ID in next comparison, traversing the message list to be processed from the first ID downwards until a message ID which is larger than or equal to the second ID in the message list to be processed is found, and taking the message ID as a first ID in next comparison;
when the comparison result between the first ID and the second ID is: and when the first ID is larger than or equal to the second ID, taking the next message ID of the second ID as the second ID in the next comparison, and taking the first ID as the first ID in the next comparison.
6. The method of any of claims 1 to 5, further comprising:
traversing the message list to be displayed, and judging whether the message IDs in the message list to be displayed are continuous or not;
when the message ID in the message list to be displayed is discontinuous or when foreground and background switching occurs in response to a chat interface, pulling a compensation message of a first time period from an offline database; all messages needing to be sent to the first client side are backed up in the offline database;
and performing message offline compensation on the message list to be displayed according to the compensation message.
7. The method of claim 6, wherein the first time period is:
when the message offline compensation is the first message offline compensation and the message offline compensation is the message offline compensation performed when the message ID in the message list to be displayed is discontinuous, the first time period is a time interval in which the receiving time of the second message is used as the starting time and the current time is used as the ending time; the second message is the previous message of the missing message in the message list to be displayed; alternatively, the first and second electrodes may be,
when the message offline compensation is the first message offline compensation and the message offline compensation is performed when the chat interface is switched between the foreground and the background, the first time period is a time interval in which the receiving time of the last message in the message list to be displayed is used as the starting time and the current time is used as the ending time; alternatively, the first and second electrodes may be,
when the message offline compensation is the subsequent message offline compensation, and the first time period is the previous message offline compensation, the receiving time of the last message in the compensation messages is used as the starting time, and the current time is used as the time interval of the ending time.
8. The method of claims 1 to 5, further comprising:
in the process that the message is transmitted through a transmission channel between a first client and a server, detecting the transmission channel in a parallel mode through a first detection method and a second detection method to detect whether the transmission channel is inactivated or disconnected, and reconnecting when the transmission channel is inactivated or disconnected;
the first detection method comprises the following steps: a plug-in used for opening a webpage in the first client monitors the transmission channel to monitor whether the transmission channel is inactivated or disconnected; the second detection method comprises the following steps: and when the first client side cannot receive the detection message repeatedly sent to the first client side by the server side at a fixed time interval within a first time length, determining that the transmission channel is inactivated or disconnected.
9. The method of claim 8, wherein the transmission channel is a WS channel, and wherein the method further comprises:
and when the WS channel exceeds a second duration and is still not successfully connected, establishing a transmission channel between the first client and the server through an HTTP protocol.
10. The method of claims 1-5, further comprising:
in the process of transmitting the message through a transmission channel between the first client and the server, the delivery confirmation of the message is carried out through an ACK mechanism;
and when the ACK response of the server is not received in the third time length, retransmitting the message.
11. A message processing device is applied to a system comprising a first client, a second client and a server, wherein the first client and the second client perform message interaction through the server, the device is arranged at the first client, and the device comprises:
the generating module is used for sequencing all the messages received in the current time period according to the message ID and generating a new message list;
an intercepting module, configured to intercept a part of a message list from an already displayed message list to serve as a to-be-processed message list, where messages in the already displayed message list are arranged according to the message ID sequence, the arrangement sequence of the messages in the already displayed message list is the same as the arrangement sequence of the messages in the new message list, a first message ID in the to-be-processed message list is smaller than a first message ID in the new message list, and a last message ID in the to-be-processed message list is a last message ID in the already displayed message list;
a comparison module, configured to compare the message IDs in the new message list with the message IDs in the to-be-processed message list, identify, from the new message list, a message ID that is not present in the to-be-processed message list, and identify an insertion position in the to-be-processed message list;
the inserting module is used for inserting the message corresponding to the identified message ID into the inserting position in the message list to be processed to generate a message list to be displayed;
and the display module is used for displaying each message in the message list to be displayed in the next time period.
12. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the computer program, when executed by the processor, implementing the method of any one of claims 1 to 10.
13. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1 to 10.
CN202111528658.6A 2021-12-14 2021-12-14 Message processing method and device, electronic equipment and readable storage medium Pending CN114221922A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111528658.6A CN114221922A (en) 2021-12-14 2021-12-14 Message processing method and device, electronic equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111528658.6A CN114221922A (en) 2021-12-14 2021-12-14 Message processing method and device, electronic equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN114221922A true CN114221922A (en) 2022-03-22

Family

ID=80701924

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111528658.6A Pending CN114221922A (en) 2021-12-14 2021-12-14 Message processing method and device, electronic equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN114221922A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110049134A (en) * 2019-04-22 2019-07-23 苏州紫焰网络科技有限公司 Customer service chat method, device, customer side, server and storage medium
CN110677468A (en) * 2019-09-23 2020-01-10 阿里巴巴集团控股有限公司 Message processing method, device and equipment
CN111884843A (en) * 2020-07-20 2020-11-03 北京字节跳动网络技术有限公司 Message processing method and device, electronic equipment and storage medium
CN112448898A (en) * 2019-08-28 2021-03-05 无锡江南计算技术研究所 Message order-preserving method based on sequence number mechanism
CN113296985A (en) * 2021-06-16 2021-08-24 北京有竹居网络技术有限公司 Message processing method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110049134A (en) * 2019-04-22 2019-07-23 苏州紫焰网络科技有限公司 Customer service chat method, device, customer side, server and storage medium
CN112448898A (en) * 2019-08-28 2021-03-05 无锡江南计算技术研究所 Message order-preserving method based on sequence number mechanism
CN110677468A (en) * 2019-09-23 2020-01-10 阿里巴巴集团控股有限公司 Message processing method, device and equipment
CN111884843A (en) * 2020-07-20 2020-11-03 北京字节跳动网络技术有限公司 Message processing method and device, electronic equipment and storage medium
CN113296985A (en) * 2021-06-16 2021-08-24 北京有竹居网络技术有限公司 Message processing method and device

Similar Documents

Publication Publication Date Title
CN110049134B (en) Customer service chat method, customer service chat device, customer service end, server and storage medium
CN108259448B (en) Method and device for preventing abnormal disconnection during wheat connection
CN115004673B (en) Message pushing method, device, electronic equipment and computer readable medium
EP1398705A1 (en) FILE DELIVERY SYSTEM, FILE DELIVERY SERVER APPARATUS, AND RECEPTION CLIENT APPARATUS
US11700291B2 (en) Automatic issue identification and status notification of screensharing in a virtual meeting
CN106161190A (en) Point-to-point instant communicating method
CN112118171A (en) Message intercommunication system, method, device, computer equipment and readable storage medium
CN111431964B (en) Message synchronous processing method, device and storage medium
CN113391979A (en) Processing method, equipment and system for monitoring data display and storage medium
CN107104822B (en) Server disaster recovery processing method and device, storage medium and electronic equipment
CN112838980B (en) Message processing method, system, device, electronic equipment and storage medium
CN111092934A (en) Method for updating client routing and storage medium
CN114221922A (en) Message processing method and device, electronic equipment and readable storage medium
CN109918210B (en) Method and terminal for displaying offline message
CN114422079B (en) Data transmission method and device, computer equipment and storage medium
CN111970340B (en) Information transmission method, readable storage medium, and electronic device
CN110233744B (en) Conference state display method, conference state updating method and device
CN108574622B (en) Instant message processing method and device based on XMPP
CN114257630B (en) Classroom real-time interaction method, system, terminal equipment and readable storage medium
CN112187868A (en) Information transmission method, readable storage medium and electronic device
CN115001630B (en) Data transmission method, device, equipment and storage medium
CN113194156B (en) Data synchronization method and system for edge device
CN113810266B (en) Retry operation method, device, equipment and storage medium for message object
CN115811506B (en) Instant messaging processing method and device
CN110011914B (en) Management message forwarding method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination