Information interaction method and device, equipment and medium
By establishing an SSE connection after receiving the first information, the problems of long wait time and waste of broadband resources in traditional information interaction are solved, and fast information acquisition and efficient information interaction are achieved.
Patent Information
- Application Number
- CN202410095975.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-23
- Publication Date
- 2025-07-25
AI Technical Summary
During the information interaction between traditional clients and servers, clients may have to wait for a long time to obtain packet back information from the server, resulting in poor user experience and waste of broadband resources.
The client sends a first information acquisition request to the server, and after receiving and displaying the first information, it sends a second information acquisition request to establish a server push event SSE connection, and gradually receives and displays the information to be sent.
Fast information acquisition is achieved through SSE connection, avoiding the long-term empty connection state of the server, improving broadband utilization and information interaction efficiency, and providing a better user experience.
Smart Images

Figure CN120378480A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technologies, and in particular, to an information interaction method, apparatus, device, and medium. Background Art
[0002] In the traditional information interaction process between a client and a server, the client sends a request to the server, and the server returns a packet, thus completing an information interaction between the client and the server. In this way, the client may need to wait for a long time to obtain the packet information returned by the server, and the user may have left the relevant page before waiting, which has an adverse impact on the user experience.
[0003] To solve the above problems, the server can establish a Server-Sent Events (SSE) connection with the client to implement real-time information pushing from the server to the client, improving the speed of information display on the client. However, in this way, the client usually establishes an SSE connection with the server at the beginning. At this time, if the server information has not been obtained yet, there will be a long idle connection state, wasting broadband resources. Summary of the Invention
[0004] To solve the above technical problems, the present disclosure provides an information interaction method, apparatus, device, and medium.
[0005] An embodiment of the present disclosure provides an information interaction method, and the method includes:
[0006] Sending a first information acquisition request to a server;
[0007] In response to receiving the first information returned by the server through a first connection, displaying the first information, and sending a second information acquisition request to the server, so that the server establishes a Server-Sent Events (SSE) connection with the client, and in response to the existence of information to be sent, sending the information to be sent to the client;
[0008] Receiving the information to be sent returned by the server through the SSE connection, and displaying the information to be sent.
[0009] Another embodiment of the present disclosure provides an information interaction method, and the method includes:
[0010] Receiving a first information acquisition request sent by a client, and sending the first information to the client through a first connection;
[0011] Receive the second information acquisition request sent by the client, establish an SSE connection with the client, and send the information to be sent to the client in response to the existence of information to be sent, where the second information acquisition request is sent by the client in response to receiving the first information.
[0012] An embodiment of the present disclosure further provides an information interaction device, the device includes:
[0013] A first request module, configured to send a first information acquisition request to the server;
[0014] A second request module, configured to, in response to receiving the first information returned by the server through the first connection, display the first information, and send a second information acquisition request to the server, so that the server establishes a Server-Sent Events (SSE) connection with the client, and send the information to be sent to the client in response to the existence of information to be sent;
[0015] A display module, configured to receive the information to be sent returned by the server through the SSE connection, and display the information to be sent.
[0016] An embodiment of the present disclosure further provides an information interaction device, the device includes:
[0017] A first receiving module, configured to receive a first information acquisition request sent by the client, and send the first information to the client through the first connection;
[0018] A second receiving module, configured to receive the second information acquisition request sent by the client, establish an SSE connection with the client, and send the information to be sent to the client in response to the existence of information to be sent, where the second information acquisition request is sent by the client in response to receiving the first information.
[0019] An embodiment of the present disclosure further provides an electronic device, the electronic device includes: a processor; a memory for storing executable instructions of the processor; the processor is configured to read the executable instructions from the memory and execute the instructions to implement the information interaction method provided by the embodiment of the present disclosure.
[0020] An embodiment of the present disclosure further provides a computer-readable storage medium, the storage medium stores a computer program, and the computer program is used to execute the information interaction method provided by the embodiment of the present disclosure.
[0021] The technical solutions provided by the embodiments of the present disclosure have the following advantages compared with the prior art: For the information interaction solution provided by the embodiments of the present disclosure, the client sends a first information acquisition request to the server; in response to receiving the first information returned by the server through the first connection, the first information is displayed, and a second information acquisition request is sent to the server, so that the server establishes a Server-Sent Events (SSE) connection with the client, and in response to the existence of information to be sent, the information to be sent is sent to the client; the information to be sent returned by the server through the SSE connection is received and displayed. By adopting the above technical solution, the client first sends a first information acquisition request to the server, displays the first information after obtaining it, and then sends a second information acquisition request to the server. After establishing the SSE connection with the server, the information to be sent sent by the server is received and displayed. This not only enables the client to quickly obtain and display information through the SSE connection, but also the client requests the SSE connection with the server to obtain the remaining information after obtaining the first information through other connections, avoiding the server having a long-term idle connection state and wasting broadband resources, and effectively improving the broadband utilization rate and information interaction efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In combination with the accompanying drawings and with reference to the following specific embodiments, the above and other features, advantages and aspects of the embodiments of the present disclosure will become more obvious. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the original elements and elements are not necessarily drawn to scale.
[0023] Figure 1 It is a schematic flowchart of an information interaction method provided by an embodiment of the present disclosure;
[0024] Figure 2 It is a schematic flowchart of another information interaction method provided by an embodiment of the present disclosure;
[0025] Figure 3 It is a schematic diagram of an information interaction provided by an embodiment of the present disclosure;
[0026] Figure 4 It is a schematic structural diagram of an information interaction device provided by an embodiment of the present disclosure;
[0027] Figure 5 It is a schematic structural diagram of another information interaction device provided by an embodiment of the present disclosure;
[0028] Figure 6 It is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0029] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although some embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Instead, these embodiments are provided to more thoroughly and completely understand the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not used to limit the protection scope of the present disclosure.
[0030] It should be understood that the various steps recited in the method embodiments of the present disclosure may be executed in a different order and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this regard.
[0031] As used herein, the term "including" and its variations are open-ended, that is, "including but not limited to". The term "based on" is "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0032] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order of functions performed by these devices, modules or units or their interdependent relationships.
[0033] It should be noted that the modifications of "one" and "multiple" mentioned in the present disclosure are illustrative rather than restrictive. Those skilled in the art should understand that unless otherwise clearly stated in the context, it should be understood as "one or more".
[0034] The information exchanged between multiple devices in the embodiments of the present disclosure or the names of the information are only for illustrative purposes and are not used to limit the scope of these information or the information.
[0035] To solve the problems existing in the information interaction process in the related art, embodiments of the present disclosure provide an information interaction method, which will be introduced below in combination with specific embodiments.
[0036] Figure 1 As shown in the flowchart of an information interaction method provided by an embodiment of the present disclosure, this method can be executed by an information interaction device, where the device can be implemented by software and / or hardware and is generally integrated in an electronic device. As Figure 1 shown, this method is applied to a client and includes:
[0037] Step 101, send a first information acquisition request to the server.
[0038] The information interaction method according to the embodiments of the present disclosure can be applicable to various information interaction scenarios between a client and a server, such as intelligent question answering. On the chat page of the client, the user communicates with an Artificial Intelligence (AI) model object. When the user sends a piece of information to the server, the server generates a corresponding answer for the user's question through the AI model and replies to the user. If the Server-Sent Events (SSE) connection is initiated too early when the user's question is sent or before it is sent, at this time the AI model has not generated an answer yet, and there will be a long empty connection state when connecting to the server earlier, and the connection will not have any response, wasting server resources and bandwidth resources.
[0039] The first information acquisition request may be a request including the user's input information for acquiring a corresponding reply information from the server.
[0040] Specifically, the client can receive the user's input information, send a first information acquisition request carrying the input information to the server. In response to the first information acquisition request, the server can establish a first connection with the client and acquire corresponding target information, such as acquiring corresponding target information using the AI model. The target information can be a general term for the information that needs to be acquired for the first information acquisition request, and the target information can correspond to the above input information. For example, if the input information is a question, the target information can be the answer to the question. Alternatively, the client can first establish a first connection with the server and send a first information acquisition request to the server through the first connection.
[0041] Optionally, after the client sends the first information acquisition request to the server, it can display a loading animation and wait for a reply. At this time, if no reply is received after exceeding a preset time, it is considered a timeout, and timeout processing is performed, and a fallback reply is displayed. For example, the preset time is 25s; if no reply is received and the user continues to ask questions, the process will be interrupted and wait for the latest reply information.
[0042] Step 102: In response to receiving the first piece of information returned by the server through the first connection, display the first piece of information, and send a second information acquisition request to the server, so that the server establishes a Server-Sent Events (SSE) connection with the client, and in response to the existence of information to be sent, send the information to be sent to the client.
[0043] Among them, the first connection is a long connection different from the SSE connection. In this embodiment of the present disclosure, the first connection is taken as an example of a Websocket long connection for illustration. The first piece of information can be the starting part information in the above-mentioned target information. There is no limit to the characters included in the first piece of information. Specifically, the information included in the first information packet obtained by the server is the first piece of information. The second information acquisition request can be a request for establishing an SSE connection with the server and acquiring the remaining information of the target information after the first piece of information. The second information acquisition request can include the position of the current information. The information to be sent can be the information that needs to be sent to the client obtained by the server in response to the above-mentioned first information acquisition request, which is the remaining information of the target information after the first piece of information. The number of information to be sent can be multiple, and the server obtains them one by one. For example, in an intelligent Q&A scenario, if the AI model generates a sentence as an answer, then this sentence is the information to be sent. Each sentence is generated one by one, and each sentence obtained by the server is used as the information to be sent.
[0044] SSE is a server push technology based on the Hyper Text Transfer Protocol (HTTP), which is used to realize the one-way communication of the server sending data to the client in real time. It allows the server to push data to the client in the form of an event stream. Compared with the traditional request method, SSE allows real-time data transmission without waiting for the completion of the entire request, can solve the problem of long waiting for the response packet in the traditional request, can send responses in packets, and the client can obtain data more quickly and display the obtained data on the screen in time, thus providing a better experience for users.
[0045] Specifically, after the client sends the first information acquisition request to the server, the server can obtain the corresponding target information. When the first piece of information is obtained, it can be returned to the client through the first connection; after the client receives the first piece of information, it can display the first piece of information and send the second information acquisition request to the server. The server can establish an SSE connection with the client and extract the position of the current information in the second information acquisition request to obtain the remaining information starting from the position of the current information. When the server obtains the information to be sent after the first piece of information, it pushes the information to be sent to the client one by one through the SSE connection.
[0046] It can be understood that in this embodiment of the present disclosure, the establishment of the first connection between the client and the server is always included and will not be interrupted to ensure the integrity of information interaction.
[0047] Step 103: Receive the information to be sent returned by the server through the SSE connection and display the information to be sent.
[0048] The client can receive the information to be sent returned by the server one by one through the SSE connection, write the information to be sent locally, and display it. When specifically displaying, the information to be sent can be stored in a queue and displayed on the screen character by character.
[0049] In this solution, after the server obtains the first piece of information and pushes it to the client, at this time, the client starts the SSE connection, and obtains the remaining information one by one through the SSE connection, avoiding the waste of server resources and broadband resources caused by an empty connection by setting the timing of starting the SSE connection.
[0050] In the information interaction solution provided by the embodiments of the present disclosure, the client sends a first information acquisition request to the server; in response to receiving the first piece of information returned by the server through the first connection, the first piece of information is displayed, and a second information acquisition request is sent to the server, so that the server establishes a Server-Sent Events (SSE) connection with the client, and in response to the existence of information to be sent, sends the information to be sent to the client; receives the information to be sent returned by the server through the SSE connection, and displays the information to be sent. By adopting the above technical solution, the client first sends a first information acquisition request to the server, displays and sends a second information acquisition request to the server after obtaining the first piece of information through the first connection, so as to establish an SSE connection with the server, and then receives and displays the information to be sent sent by the server. Not only can the client quickly obtain and display information through the SSE connection, but also the client requests an SSE connection with the server to obtain the remaining information after obtaining the first piece of information through other connections, avoiding the server from being in an empty connection state for a long time and wasting broadband resources, effectively improving the broadband utilization rate and information interaction efficiency.
[0051] In some embodiments, after receiving the information to be sent returned by the server through the SSE connection and displaying the information to be sent, the method further includes: receiving the target information returned by the server through the first connection, where the target information is sent by the server in response to the information to be sent including the last piece of information, and the target information includes the first piece of information and all the subsequent information to be sent.
[0052] The target information can be a general term for the information that needs to be acquired by the first information acquisition request, and can include the above-mentioned first piece of information and all the subsequent information to be sent. The last piece of information can be the ending part information of the target information, that is, when the server obtains the last piece of information, it means that all the target information has been obtained.
[0053] After the client starts to receive the information to be sent, it can receive the target information sent by the server in response to the information to be sent including the last piece of information and store it locally.
[0054] Optionally, the information interaction method may further include: if the target information is received when the last information returned by the server through the SSE connection has been displayed, then replace all the displayed information with the target information for display.
[0055] Optionally, the information interaction method may further include: if the target information is received before the last information returned by the server through the SSE connection, then store the target information locally.
[0056] While receiving the information to be sent through the SSE connection, the client can also receive the target information sent through the first connection. If the last information is received first through the SSE connection and the target information is received after the last information has been displayed, then the previously displayed all information can be replaced with the target information for refreshed display, avoiding the problem of incomplete overall information caused by possible loss of some information in the SSE connection, and improving the reliability of information interaction.
[0057] If the last information has not been received through the SSE connection and the target information is received, the target information can be not processed at this time, and only the target information is stored locally, and continue to receive the information to be sent through the SSE connection until the last information is received and displayed. By the above method, the smoothness of receiving and displaying the streaming information is not interrupted, the smoothness of information display is ensured, and thus the user experience effect is improved.
[0058] In addition, after the client receives the first information and the information to be sent through the SSE connection, they are both written locally. When writing, it can be judged whether the information locally is the target information. If so, the writing is not executed, otherwise, the writing is executed to update the local information.
[0059] The client receives the first information of the target information through the first connection, the subsequent information to be sent is obtained through the SSE connection, and the complete target information is also received through the first connection, ensuring that even if the client is interrupted or abnormal during the process of receiving information, the integrity of the data can be achieved through the complete information of the long connection pushed by the server; and when the client finishes obtaining data through the SSE connection and receives the target data through the first connection, the most suitable data can be used in combination with the actual situation, which can not only avoid the loss of information, but also ensure the smoothness of information display and the multi-terminal synchronization effect.
[0060] In some embodiments, the information interaction method may further include: if the information to be sent returned by the server through the SSE connection is the last information, then send a disconnection request of the SSE connection to the server to disconnect the SSE connection between the server and the client.
[0061] When the client receives the last message of the target message among the messages to be sent, it can send a disconnection request for the SSE connection to the server, and the server can disconnect the SSE connection with the client. Alternatively, when the server sends the message to be sent and the message to be sent is the last message of the target message, it can actively disconnect the SSE connection with the client.
[0062] The client starts the SSE connection after receiving the first message sent by the server, and disconnects the SSE connection after receiving the last message, further avoiding the waste of broadband resources caused by the idle connection state of the SSE connection.
[0063] In some embodiments, the information interaction method may further include: when presenting the first message or the message to be sent, outputting and presenting the pause punctuation with a first duration, and outputting and presenting the remaining characters other than the pause punctuation with a second duration, where the first duration is greater than the second duration.
[0064] Among them, the pause punctuation may be a punctuation mark with a pause meaning, and specifically may include a comma, a period, a document number, an exclamation mark, etc. The first duration may be the duration when the pause punctuation is presented, the second duration may be a preset character presentation duration, and the first duration is greater than the second duration. For example, the first duration may be 100 ms, and the second duration may be 20 ms.
[0065] When the client presents the first message or the message to be sent in the target message, it can output and present the pause punctuation with a first duration, and output and present the remaining characters other than the pause punctuation with a second duration, realizing the alienation processing of a slight pause when presenting the pause punctuation, improving the information presentation effect, and further improving the user experience effect, giving the user a stronger sense of narration.
[0066] Figure 2 It is a schematic flowchart of another information interaction method provided by an embodiment of the present disclosure. This method can be executed by an information interaction device, where the device can be implemented by software and / or hardware and is generally integrated in an electronic device. As Figure 2 shown, this method is applied to the server and includes:
[0067] Step 201, receive a first information acquisition request sent by the client, and send the first message to the client through the first connection.
[0068] The client can receive the input information of the user, send a first information acquisition request carrying the input information to the server, and the server responds to the first information acquisition request, establishes a first connection with the client, and can obtain the corresponding target information. When obtaining the first message, it can be returned to the client through the first connection.
[0069] Step 202: Receive a second information acquisition request sent by the client, establish an SSE connection with the client, and send the information to be sent to the client in response to the existence of information to be sent, where the second information acquisition request is sent by the client after receiving the first piece of information.
[0070] After receiving the first piece of information, the client can display the first piece of information and send a second information acquisition request to the server; the server can establish an SSE connection with the client, and when there is information to be sent after receiving the first piece of information, push the information to be sent to the client one by one through the SSE connection.
[0071] In some embodiments, the information interaction method may further include: in response to the information to be sent including the last piece of information, send target information to the client through a first connection, where the target information includes the first piece of information and all subsequent information to be sent.
[0072] In response to the information to be sent including the last piece of information, the server may send the complete target information to the client. The client may store the target information locally and use the target data or the information to be sent received through the SSE connection according to the actual situation.
[0073] In the information interaction solution provided by the embodiments of the present disclosure, the server receives a first information acquisition request sent by the client and sends the first piece of information to the client through a first connection; receives a second information acquisition request sent by the client, establishes an SSE connection with the client, and sends the information to be sent to the client in response to the existence of information to be sent, where the second information acquisition request is sent by the client after receiving the first piece of information. By adopting the above technical solution, the server responds to the first information acquisition request sent by the client based on the first connection and sends the first piece of information. Then the client displays and sends a second information acquisition request to the server. After the server establishes an SSE connection with the client, it sends the information to be sent to the client for display. This not only enables the client to quickly acquire and display information through the SSE connection, but also the client requests an SSE connection with the server to acquire the remaining information after obtaining the first piece of information through other connections, avoiding the server having a long-term idle connection state and wasting broadband resources, and effectively improving broadband utilization and information interaction efficiency.
[0074] Next, a specific example is used to further illustrate the information interaction method of the embodiments of the present disclosure. Exemplarily, Figure 3 is a schematic diagram of information interaction provided by the embodiments of the present disclosure, as Figure 3As shown in the figure, the information interaction process between the client and the server is demonstrated by taking the intelligent Q&A scenario as an example. The client in the figure may include a user interface, SSE, SDK (Software Development Kit), and a network layer. The AI model can be set on the server or externally, and there is no specific limitation. The specific information interaction process may include:
[0075] 1. The user interface of the client receives the question "Who are you" input by the user through the input box, and then uses the long connection (i.e., the above-mentioned first connection) through SSE and SDK to send the information including the question (i.e., the first information acquisition request) to the server; at this time, if the first information acquisition request fails to be sent, the loading animation in step 3 will not be displayed.
[0076] 2. The server receives the first information acquisition request, sends an information reply packet to the client, and forwards the question to the AI model, requesting the model to generate information.
[0077] 3. The client starts to display the loading animation and waits for the reply.
[0078] The following special situations may exist here:
[0079] a. If no reply is received after more than 25s, it is considered that the model has timed out, and timeout processing is performed to display a fallback reply;
[0080] b. If the AI model has not replied and the user continues to ask questions, the process will be interrupted, and wait for the AI to reply with the latest information.
[0081] 4. The AI model generates an answer based on the user's question and returns it to the server packet by packet through a callback.
[0082] 5. The server pushes the first packet to the client through the first connection. Here, the first packet is the information packet including the above-mentioned first piece of information. The first piece of information is, for example, "My name is" in the figure.
[0083] 6. After receiving the first packet, the client disappears the loading animation, puts the first piece of information received into the queue, waits for the words to be displayed on the screen one by one, and synchronously triggers the SSE logic to start the SSE pull request (i.e., send the second information acquisition request to the server) to request the data of each subsequent packet after the first packet. And the current data position 5 is included in this request, just for example.
[0084] The following special situations may exist here:
[0085] a. If there are situations such as network disconnection or interface failure during the request process of the SSE connection, try to reconnect up to 3 times, and request the information again from the position where the information was disconnected;
[0086] b. If the interval time exceeds 25s, it is considered that this request has timed out, and timeout handling is performed to display the fallback response;
[0087] c. If the user asks a question during the output display process, the output display will be interrupted, the fallback response will be displayed, and the server will be informed that the display has been interrupted;
[0088] d. When exiting the page during the output process, if the model has completed answering when entering the page next time, the complete content will be displayed, that is, the target information will be displayed. Otherwise, the remaining information will be pulled again from the disconnection point;
[0089] e. If the SSE connection is abnormally interrupted and there is still information not received, and during the process of preparing to reconnect to the SSE, the target information pushed by the first connection is received, the SSE connection can be skipped.
[0090] 7. After the server receives the stream pulling request for the SSE connection, it obtains the remaining information from the AI model, that is, the above-mentioned information to be sent, and returns it to the client in packets, that is, returns the information to the client one by one.
[0091] 8. After the client receives the information packet, it writes it into the local database cache from the business layer, that is, into the SDK data in the figure, and queues it up to be displayed word by word on the screen.
[0092] 9. After the AI model has finished pushing, the client disconnects the SSE stream pulling request
[0093] 10. The server pushes the complete information (that is, the target information in the final state) to the client through the long connection, and uses both the first connection and the SSE connection to ensure that the information is received normally and completely on the client side.
[0094] After the server receives the last piece of information from the AI model, it will immediately return the complete information to the client through the long connection via the information chain. The information pushed down by the long connection of the information chain on the client side will be directly written into the local database cache and thrown up to the business layer to notify the business layer that the information has been updated.
[0095] When the client finishes obtaining data through the SSE connection and receives the target data through the first connection, it can use the most suitable data according to the actual situation. Specifically, 1) If the streaming through the SSE connection is completed first and the information has been displayed on the screen, and at this time, the complete information pushed by the long connection is received, and it is judged that the information being displayed on the screen has been completed, then the information of the long connection is used to replace the information being displayed on the screen and refreshed on the screen to avoid the problem of incomplete information caused by the loss of a small segment of the information pulled through the SSE connection; 2) If the streaming through the SSE connection has not been completed and the information is still being displayed word by word on the screen, and at this time, the complete information pushed by the long connection is received, and after notifying the business layer, the business layer judges that the current is in the streaming process. In order to ensure a smooth streaming experience without interruption, the streaming output continues until the output is completed. This time, the complete information pushed by this long connection is not processed and only stored locally.
[0096] During the process of writing the information obtained during the SSE streaming into the local database cache, it will be judged whether the information in the local database cache is already the complete information pushed by the long connection. If so, the local cache will not be updated and the complete information pushed by the long connection will be used as the standard; otherwise, the local database cache will be updated.
[0097] In the above solution, when the AI model generates the first packet and pushes it to the client through the server, at this time, the client starts the SSE connection to obtain the remaining information packet by packet. At this time, the AI model will continue to output the remaining information at the right time, which can not only avoid wasting broadband resources, but also transmit information in real time through the SSE connection. The client can obtain data more quickly and display the obtained data on the screen in time, thus providing a better experience for users. And the first packet and the complete information are pushed down in real time through the long connection, and the remaining packets are actively pulled through the SSE connection, ensuring that even if the client is interrupted or has an exception during the process of actively pulling the remaining packets, the integrity of the information and the multi-terminal synchronization effect can be achieved through the complete information packet pushed by the server.
[0098] Figure 4 The following is a schematic structural diagram of an information interaction device provided by an embodiment of the present disclosure. The device can be implemented by software and / or hardware and is generally integrated in an electronic device. As Figure 4 shown, the device includes:
[0099] A first request module 401, configured to send a first information acquisition request to a server;
[0100] A second request module 402, configured to, in response to receiving the first information returned by the server through the first connection, display the first information, and send a second information acquisition request to the server, so that the server establishes a server-sent events (SSE) connection with the client, and in response to the existence of information to be sent, send the information to be sent to the client;
[0101] A display module 403, configured to receive the information to be sent returned by the server through the SSE connection, and display the information to be sent.
[0102] Optionally, the first connection is a long connection different from the SSE connection.
[0103] Optionally, the apparatus further comprises an information receiving module, configured to: after receiving the information to be sent returned by the server through the SSE connection and displaying the information to be sent,
[0104] receive target information returned by the server through the first connection, where the target information is that the server responds to the presence of the last information among the information to be sent, and the target information includes the first information and all the subsequent information to be sent.
[0105] Optionally, the apparatus further comprises a replacement module, configured to:
[0106] if all the information already displayed is the last information returned by the server through the SSE connection when the target information is received, replace all the already displayed information with the target information for display.
[0107] Optionally, the apparatus further comprises a storage module, configured to:
[0108] if the last information returned by the server through the SSE connection has not been received when the target information is received, store the target information locally.
[0109] Optionally, the apparatus further comprises a disconnection module, configured to:
[0110] if the information to be sent returned by the server through the SSE connection is the last information, send a disconnection request for the SSE connection to the server, so that the server disconnects the SSE connection from the client.
[0111] Optionally, the apparatus further comprises a display module, configured to:
[0112] when displaying the first information or the information to be sent, output and display the pause punctuation with a first duration, and output and display the remaining characters except the pause punctuation with a second duration, where the first duration is greater than the second duration.
[0113] The information interaction apparatus provided by the embodiments of the present disclosure can execute the information interaction method provided by any embodiment of the present disclosure, and has corresponding functional modules and beneficial effects for executing the method.
[0114] Figure 5 A schematic structural diagram of another information interaction device provided by an embodiment of the present disclosure. The device can be implemented by software and / or hardware and is generally integrated in an electronic device. As Figure 5 shown, the device includes:
[0115] A first receiving module 501, configured to receive a first information acquisition request sent by a client and send a first piece of information to the client through a first connection;
[0116] A second receiving module 502, configured to receive a second information acquisition request sent by the client, establish an SSE connection with the client, and send the to-be-sent information to the client in response to the existence of to-be-sent information, where the second information acquisition request is sent by the client in response to receiving the first piece of information.
[0117] Optionally, the device further includes a push module, configured to:
[0118] In response to the to-be-sent information including the last piece of information, send target information to the client through the first connection, where the target information includes the first piece of information and all the subsequent to-be-sent information.
[0119] The information interaction device provided by an embodiment of the present disclosure can execute the information interaction method provided by any embodiment of the present disclosure, and has corresponding functional modules and beneficial effects for executing the method.
[0120] An embodiment of the present disclosure further provides a computer program product, including a computer program / instructions, where when the computer program / instructions are executed by a processor, the information interaction method provided by any embodiment of the present disclosure is implemented
[0121] Figure 6 A schematic structural diagram of an electronic device provided by an embodiment of the present disclosure.
[0122] Specifically, referring to Figure 6 , which shows a schematic structural diagram of an electronic device 600 suitable for implementing an embodiment of the present disclosure. The electronic device 600 in an embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Tablet Computers), PMPs (Portable Multimedia Players), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The electronic device shown is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present disclosure.
[0123] As Figure 6As shown, the electronic device 600 may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 601, which may perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other through a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0124] Generally, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or wiredly to exchange data. Although Figure 6 the electronic device 600 with various devices is shown, it should be understood that it is not required to implement or have all the shown devices. Instead, more or fewer devices may be implemented or had.
[0125] Specifically, according to an embodiment of the present disclosure, the process described above with reference to the flowchart may be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes program codes for performing the method shown in the flowchart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication device 609, or installed from the storage device 608, or installed from the ROM 602. When the computer program is executed by the processing device 601, the above functions defined in the information interaction method of the embodiment of the present disclosure are executed.
[0126] It should be noted that the above-mentioned computer-readable medium in the present disclosure can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, the computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system, apparatus, or device. In the present disclosure, the computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, in which computer-readable program code is carried. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and this computer-readable signal medium can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0127] In some embodiments, the client and the server can communicate using any currently known or future-developed network protocol such as HTTP (HyperText Transfer Protocol), and can be interconnected with digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include local area networks ("LANs"), wide area networks ("WANs"), the Internet (e.g., the Internet), and end-to-end networks (e.g., ad hoc end-to-end networks), as well as any currently known or future-developed networks.
[0128] The above-mentioned computer-readable medium can be included in the above-mentioned electronic device; it can also exist separately and not be assembled into the electronic device.
[0129] The above computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to: send a first information acquisition request to the server; in response to receiving the first information returned by the server via the first connection, display the first information, and send a second information acquisition request to the server, so that the server establishes a Server-Sent Events (SSE) connection with the client, and in response to the existence of information to be sent, send the information to be sent to the client; receive the information to be sent returned by the server via the SSE connection, and display the information to be sent.
[0130] Alternatively, the above computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to: receive a first information acquisition request sent by the client, and send the first information to the client via the first connection; receive a second information acquisition request sent by the client, establish an SSE connection with the client, and in response to the existence of information to be sent, send the information to be sent to the client, where the second information acquisition request is sent by the client in response to receiving the first information.
[0131] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or combinations thereof. The programming languages include, but are not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., by using an Internet service provider to connect through the Internet).
[0132] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a portion of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur in a different order than noted in the drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or by a combination of dedicated hardware and computer instructions.
[0133] The units involved in the embodiments described in the present disclosure can be implemented in software or in hardware. In some cases, the name of the unit does not constitute a limitation on the unit itself.
[0134] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. By way of example, and without limitation, the types of hardware logic components that may be used include: field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems on a chip (SOCs), complex programmable logic devices (CPLDs), and the like.
[0135] In the context of the present disclosure, a machine-readable medium may be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0136] It should be understood that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, usage scopes, usage scenarios, etc. of the information involved in the present disclosure should be informed to users and the authorization of users should be obtained in an appropriate manner in accordance with relevant laws and regulations.
[0137] The above description is only a preferred embodiment of the present disclosure and an explanation of the applied technical principles. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above technical features, and should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosure concept. For example, the technical solutions formed by mutually replacing the above features with the technical features (but not limited to) having similar functions disclosed in the present disclosure.
[0138] In addition, although the operations are depicted in a particular order, this should not be construed as requiring that the operations be performed in the particular order shown or in sequential order. In certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the present disclosure. Certain features described in the context of separate embodiments may also be implemented combinatorially in a single embodiment. Conversely, the various features described in the context of a single embodiment may also be implemented separately or in any suitable sub-combination in multiple embodiments.
[0139] Although the subject matter has been described in language specific to structural features and / or methodological logical acts, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. On the contrary, the specific features and acts described above are merely example forms for implementing the claims.
Claims
1. An information interaction method, characterized in that, including: sending a first information acquisition request to the server; in response to receiving the first information returned by the server through the first connection, presenting the first information, and sending a second information acquisition request to the server, so that the server establishes a Server-Sent Events (SSE) connection with the client, and in response to the existence of information to be sent, sending the information to be sent to the client; receiving the information to be sent returned by the server through the SSE connection, and presenting the information to be sent.
2. The method according to claim 1, wherein The first connection is a long connection different from the SSE connection.
3. The method according to claim 1, wherein After receiving the information to be sent returned by the server through the SSE connection and presenting the information to be sent, the method further includes: receiving target information returned by the server through the first connection, where the target information is sent by the server in response to the existence of the last piece of information among the information to be sent, and the target information includes the first information and all subsequent information to be sent.
4. The method according to claim 3, wherein The method further includes: if the last piece of information returned by the server through the SSE connection has been presented when the target information is received, replacing all the presented information with the target information for presentation.
5. The method according to claim 3, wherein The method further includes: if the last piece of information returned by the server through the SSE connection has not been received when the target information is received, storing the target information locally.
6. The method according to claim 1, wherein The method further includes: if the information to be sent returned by the server through the SSE connection is the last piece of information, sending a disconnection request for the SSE connection to the server, so that the server disconnects the SSE connection from the client.
7. The method according to claim 1, wherein The method further includes: when presenting the first information or the information to be sent, outputting and presenting the pause punctuation with a first duration, and outputting and presenting the remaining characters except the pause punctuation with a second duration, where the first duration is greater than the second duration.
8. An information interaction method, characterized in that including: receiving a first information acquisition request sent by the client, and sending the first information to the client through the first connection; receiving the second information acquisition request sent by the client, establishing an SSE connection with the client, and in response to the existence of information to be sent, sending the information to be sent to the client, where the second information acquisition request is sent by the client in response to receiving the first information.
9. The method according to claim 8, characterized in that, The method further includes: in response to the existence of the last piece of information among the information to be sent, sending target information to the client through the first connection, where the target information includes the first information and all subsequent information to be sent.
10. An information interaction device, characterized in that, including: a first request module, configured to send a first information acquisition request to the server; a second request module, configured to, in response to receiving the first information returned by the server through the first connection, present the first information, and send a second information acquisition request to the server, so that the server establishes an SSE connection with the client, and in response to the existence of information to be sent, send the information to be sent to the client; A display module, configured to receive the information to be sent returned by the server through the SSE connection and display the information to be sent.
11. An information interaction device, characterized in that, It includes: A first receiving module, configured to receive a first information acquisition request sent by a client and send a first piece of information to the client through a first connection; A second receiving module, configured to receive a second information acquisition request sent by the client, establish an SSE connection with the client, and send the information to be sent to the client in response to the existence of the information to be sent, where the second information acquisition request is sent by the client in response to receiving the first piece of information.
12. An electronic device, characterized in that, The electronic device includes: A processor; A memory for storing executable instructions of the processor; The processor is configured to read the executable instructions from the memory and execute the instructions to implement the information interaction method according to any one of claims 1-9 above.
13. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, and the computer program is used to execute the information interaction method according to any one of claims 1-9 above.
Citation Information
Cited By
Method for realizing interaction control among Web side, server side and control side
CN120935155A