Background
In recent years, a real-time communication system using a browser as a client has been accepted by a large number of users due to the characteristics of convenience, simplicity, no limitation and the like. But due to the characteristics of the browser, the aspects of instant information, state, message notification and the like of the browser cannot be synchronized with the client in real time. Therefore, the method solves the problem of real-time synchronization of the information of the browser client and the information of the server, and is one of the metrics for improving the user experience of browser products.
Currently, a browser client acquires data in an interactive mode of a "pull" mode under HTTP (hypertext transfer protocol), that is, the browser client sends an HTTP request to a server at regular time. After receiving the HTTP request, the server checks whether data needing to be returned exists locally. And if the data needing to be returned exist, the server returns the data to the client through the HTTP response. Obviously, the pull mode is a passive mode for the server to send data to the client, and when new data occurs in the server, the new data cannot be sent to the browser client without receiving an HTTP request. In view of the above, there is a need to implement more interactive ways based on the HTTP protocol so that the server can more flexibly send data to the client.
Content of the specification
An object of the embodiments of the present specification is to provide an interaction method, a client device, and a server device, which can implement more interaction modes based on an HTTP protocol, so that the server can transmit data to the client more flexibly.
In order to achieve the above purpose, the embodiments of the present specification adopt the following technical solutions:
in a first aspect, an embodiment of the present specification provides an interaction method applied to a client, including:
sending a first hypertext transfer protocol (HTTP) request of an interactive mode to a server, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
receiving an HTTP response sent by a server, wherein the HTTP response carries response data of the first HTTP request and an identifier of the first HTTP request;
and processing the first HTTP request according to the response data of the first HTTP request in the HTTP response and the identification of the first HTTP request.
In a second aspect, an embodiment of the present specification provides an interaction method applied to a server, including:
receiving a first HTTP request of an interactive mode initiated by a client, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
and sending an HTTP response to the client according to the information of the interactive mode in the first HTTP request and the information for determining the response data of the first HTTP request, wherein the HTTP response carries the identifier of the first HTTP request and the response data of the first HTTP request.
In a third aspect, an embodiment of the present specification provides a client device, including:
the request sending module is used for sending a first HTTP request of an interactive mode to a server, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
the response receiving module is used for receiving an HTTP response sent by a server, wherein the HTTP response carries response data of the first HTTP request and the identifier of the first HTTP request;
and the processing module is used for processing the first HTTP request according to the response data of the first HTTP request in the HTTP response and the identifier of the first HTTP request.
In a fourth aspect, an embodiment of the present specification provides a server device, including:
the request receiving module is used for receiving a first HTTP request of an interactive mode initiated by a client, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
and the response sending module is used for sending an HTTP response to the client according to the information of the interaction mode in the first HTTP request and the information for determining the response data of the first HTTP request, wherein the HTTP response carries the identifier of the first HTTP request and the response data of the first HTTP request.
In a fifth aspect, an embodiment of the present specification provides a client device, including: the method comprises the following steps: a memory, a processor, and a computer program stored on the memory and running on the processor, the computer program when executed by the processor implementing the steps of:
sending a first HTTP request of an interactive mode to a server, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
receiving an HTTP response sent by a server, wherein the HTTP response carries response data of the first HTTP request and an identifier of the first HTTP request;
and processing the first HTTP request according to the response data of the first HTTP request in the HTTP response and the identification of the first HTTP request.
In a sixth aspect, an embodiment of the present specification provides a server device, including: a memory, a processor, and a computer program stored on the memory and running on the processor, the computer program when executed by the processor implementing the steps of:
receiving a first HTTP request of an interactive mode initiated by a client, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
and sending an HTTP response to the client according to the information of the interactive mode in the first HTTP request and the information for determining the response data of the first HTTP request, wherein the HTTP response carries the identifier of the first HTTP request and the response data of the first HTTP request.
In a seventh aspect, an embodiment of the present specification provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when executed by a processor, the computer program implements the following steps:
sending a first HTTP request of an interactive mode to a server, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
receiving an HTTP response sent by a server, wherein the HTTP response carries response data of the first HTTP request and an identifier of the first HTTP request;
and processing the first HTTP request according to the response data of the first HTTP request in the HTTP response and the identification of the first HTTP request.
In an eighth aspect, the present specification provides a computer-readable storage medium, on which a computer program is stored, and when executed by a processor, the computer program implements the following steps:
receiving a first HTTP request of an interactive mode initiated by a client, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
and sending an HTTP response to the client according to the information of the interactive mode in the first HTTP request and the information for determining the response data of the first HTTP request, wherein the HTTP response carries the identifier of the first HTTP request and the response data of the first HTTP request.
The embodiment of the specification adopts at least one technical scheme which can achieve the following beneficial effects:
the embodiment of the specification adds information of an interactive mode and an identification of an HTTP request on the basis of an original HTTP request, so that after the server receives the HTTP request, an HTTP response is returned to the client according to the interactive mode indicated by the HTTP request, and the identification of the HTTP request is carried in the HTTP response, so that after the client receives the HTTP response, the HTTP request corresponding to response data is matched according to the identification of the HTTP request in the HTTP response, the HTTP request is processed according to the response data, and an interactive process is completed. Obviously, the embodiments of the present description implement communication in different interactive modes based on the HTTP protocol, and the server may send data to the client in an active mode in addition to sending data to the client in an original passive mode, thereby ensuring timeliness of data sending. In addition, the client can accurately find the HTTP request matched with the response data due to the identification of the HTTP request, so that the HTTP response returned by the server once can carry the response data of a plurality of HTTP requests, the sending efficiency of downlink data is improved, and the phenomenon of data return delay of the server is effectively avoided in the scene of sudden increase of HTTP requests.
Detailed Description
In order to make the objects, technical solutions and advantages of the present disclosure more clear, the technical solutions of the present disclosure will be clearly and completely described below with reference to the specific embodiments of the present disclosure and the accompanying drawings. It is to be understood that the embodiments described are only a few embodiments of the present disclosure, and not all embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present specification without any creative effort belong to the protection scope of the present specification.
The technical solutions provided by the embodiments of the present description are described in detail below with reference to the accompanying drawings.
As mentioned above, in HTTP, a browser client (hereinafter, referred to as a client) acquires data in an interactive manner in a pull mode. The pull mode is also called a request mode, and is a question-and-answer mechanism, when new data exists in the server, the server needs the browser client to initiate an HTTP request first, and then can return the data to the client through an HTTP response. In practical application, in order to avoid generating excessive overhead for the server, the client does not frequently send HTTP requests to the server, and therefore when new data is sent out by the server, the new data cannot be returned to the client in time.
In order to ensure that the client can acquire data in time, the embodiment of the present specification improves communication of HTTP, so that HTTP is no longer limited to an interactive mode of a pull mode, for example, an interactive mode of a push mode and a long polling mode, in which a server actively sends data to the client, may also be used.
In one aspect, an embodiment of the present specification provides a method applied to client interaction, as shown in fig. 1, including:
step 102, sending a first HTTP request of an interactive mode to a server, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
for step 102:
the interaction mode of the first HTTP request is not limited to the pull mode described above, and may also be an interaction mode in which the server actively sends data to the client, such as a push mode and a long polling mode. Therefore, the first HTTP request needs to carry information of the interaction mode to indicate the interaction mode applied by the first HTTP request to the server, so that the server also follows the interaction mode to return an HTTP response.
In addition, the first HTTP request carries an identifier of the server, so that the server associates the response data of the first HTTP request with the identifier of the first HTTP request and returns the association to the client after obtaining the response data of the first HTTP request. After receiving the response data returned by the server, the client can match the first HTTP request corresponding to the response data according to the identifier of the first HTTP request associated with the response data. In practical applications, the Identifier of the first HTTP request may be a Unique feature of the first HTTP request, such as a timestamp of the first HTTP request, a Universally Unique Identifier (UUID) of the first HTTP request, and the like.
In addition, information determining response data of the first HTTP request may be flexibly set according to an interactive manner. For example, the interaction mode of the request mode is a question-and-answer mechanism, and the server needs to respond after receiving the first HTTP request, so that the first HTTP request is sent in the request mode and is generally used for acquiring data currently existing in the server, and therefore, the information for determining the response data of the first HTTP request may be information directly and explicitly indicating the data that the client needs to acquire. For the interactive mode of the push mode and the long polling mode, the connection is established between the server and the client, and when the server generates new data, the HTTP response is actively sent to the client through the connection. As can be seen, the push mode and the long polling mode send the first HTTP request to obtain data subsequently generated by the server, so that the information for determining the response data of the first HTTP request may be information of a service event triggering the response data, and the server may follow and/or process the service event according to the information of the service event, thereby obtaining the response data triggered by the service event.
Step 104, receiving an HTTP response sent by the server, wherein the HTTP response carries an identifier of the first HTTP request and response data associated with the identifier of the first HTTP request;
for step 104:
the server side returns the HTTP response according to the interactive mode of the first HTTP request. As an exemplary introduction, if the first HTTP request is an interactive manner of a request mode, the server returns an HTTP response to the client according to a response rule of the request mode; for another example, if the first HTTP request is in an interactive manner in the long polling mode, the server returns an HTTP response to the client according to a response rule in the long polling mode.
Step 106, processing the first HTTP request according to the identifier of the first HTTP request and the response data associated with the identifier of the first HTTP request in the HTTP response.
For step 106:
the client matches a first HTTP request according to the identifier of the first HTTP request in the HTTP response; and then processing the matched first HTTP request according to response data which is associated with the identifier of the first HTTP request in the HTTP response.
In practical application, the client may concurrently send a plurality of HTTP requests to the server using at least one interactive manner, and correspondingly, may also receive HTTP responses triggered by different HTTP requests returned by the server. Based on the identity of the HTTP request in the HTTP response, different response data can be simply and efficiently associated to the correct HTTP request.
It should be noted that.
The HTTP response of this embodiment may return response data of one HTTP request at a time, that is, the HTTP response carries an identifier of one HTTP request and response data associated with the identifier of the HTTP request. After receiving the HTTP response, the server may match which HTTP request corresponds to the response data in the HTTP response according to the identifier of the HTTP request in the HTTP response, and then process and match the HTTP request according to the response data.
Alternatively, the first and second electrodes may be,
the HTTP response of this embodiment may return response data of at least two HTTP requests at a time, that is, the HTTP response carries the response data of at least two HTTP requests and the identifiers of at least two HTTP requests associated with the response data one by one. After receiving the HTTP response, the server may match corresponding HTTP requests for different response data in the HTTP response according to the identifier of the HTTP request in the HTTP response, and then process the matched HTTP requests according to the response data.
In summary, the interaction method of this embodiment adds information of an interaction manner and an identifier of an HTTP request on the basis of an original HTTP request, so that after receiving the HTTP request, a server returns an HTTP response to a client according to the interaction manner indicated by the HTTP request, and the HTTP response carries the identifier of the HTTP request, so that after receiving the HTTP response, the client matches an HTTP request corresponding to response data according to the identifier of the HTTP request in the HTTP response, and processes the HTTP request according to the response data. Obviously, the embodiments of the present description implement communication in different interactive modes based on the HTTP protocol, and the server may send data to the client in an active mode in addition to sending data to the client in an original passive mode, thereby ensuring timeliness of data sending.
Specifically, in this embodiment, the client may adopt an interactive mode including one of a request mode, a push mode, and a long polling mode.
Wherein the content of the first and second substances,
the request mode, i.e. the pull mode introduced above, specifies that the client and the server use a question-and-answer mechanism. Namely, after the client sends the first HTTP request in the request mode, the server immediately processes the first HTTP request, and returns the response data obtained by the processing to the client through the HTTP response.
The long polling mode is that a client initiates a first HTTP request of the long polling mode to a server, establishes a connection channel of the long polling mode, and holds the connection channel if the server does not have response data at the time until the server obtains the response data or waits for a certain time to be overtime, and returns an HTTP response in an active manner through the connection channel. And when the client receives the HTTP response through the connection channel, sending a new round of second HTTP request in the long polling mode to the server, so that the server returns response data corresponding to the second HTTP request based on the second HTTP request.
The push mode refers to that after a first HTTP request of the push mode is sent by a client, the first HTTP request is processed, and after response data are obtained, response data are returned to the client in an active mode.
Correspondingly, an embodiment of the present specification further provides an interaction method applied to a server, as shown in fig. 2, including:
step 202, receiving a first HTTP request of an interactive mode initiated by a client, where the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request, and information for determining response data of the first HTTP request;
for step 202:
the interaction mode of the first HTTP request may be flexibly set by the client, and may be one of the request mode, the push mode, and the long polling mode. The identity of the first HTTP request may be a unique characteristic of the first HTTP request, such as a timestamp of the first HTTP request, a UUID of the first HTTP request, and so forth.
Step 204, sending an HTTP response to the client according to the information of the interaction mode in the first HTTP request and the information of the response data determining the first HTTP request, where the HTTP response carries the identifier of the first HTTP request and the response data of the first HTTP request.
For step 204:
the server determines the interaction mode of the first HTTP request according to the information of the interaction mode in the first HTTP request, and obtains the response data of the first HTTP request according to the information of the response data of the first HTTP request in the first HTTP request. And then, according to the determined interaction mode, sending an HTTP response carrying the identification of the first HTTP request and response data of the first HTTP request to the client.
And the response data of the first HTTP request has an association relation with the identification of the first HTTP request. The HTTP response may carry response data of at least two different HTTP requests at a time, and the response data are respectively associated with the respective corresponding HTTP request identifiers. When the client receives the HTTP response, the client matches the correct HTTP request for the different response data according to the incidence relation between the different response data in the HTTP response and the identification of the different HTTP request, and the corresponding HTTP request can be processed through the response data after matching. Obviously, the once returned HTTP response may carry response data of a plurality of different HTTP requests, which may improve the efficiency of the server sending downlink data, and further effectively avoid the server from having a data return delay in the HTTP request burst scenario.
Step 204 is described in detail below.
Exemplarily, the following steps are carried out:
the step of sending the HTTP response to the client by the server according to the request mode specifically comprises the following steps: and sending the HTTP response of the request mode to the client according to a question-and-answer mechanism of the HTTP response.
The server sends an HTTP response to the client according to the long polling mode, and the HTTP response comprises the following steps: when a first HTTP request is received, establishing and suspending a connection channel in a long polling mode with a client, and associating the connection channel with an identifier of the client; when response data are obtained, matching a suspended connection channel according to the identification of the client; and sending the HTTP response of the long polling mode to the client by using the matched connection channel. The client identifier may be carried by the first HTTP request, and the server obtains the client identifier from the first HTTP request.
The server side sends an HTTP response to the client side according to the push mode, and the HTTP response comprises the following steps: and when the response data is obtained and a connection channel of the long polling mode with the client is established based on other HTTP requests, sending an HTTP response of the long polling mode to the client by using the connection channel.
It can be seen that, in this embodiment, the push mode only has uplink transmission in the push mode, and the downlink transmission multiplexes the connection channel in the long polling mode. That is, after processing the first HTTP request in push mode, the server returns an HTTP response in long polling mode to the client.
Based on the above design, the uplink transmission in the push mode in this embodiment can be regarded as a supplement to the long polling mode, and the problem that the HTTP request cannot be initiated again without returning an HTTP response after the connection channel is established in the long polling mode is solved.
The interaction method in this specification will be described in detail in a practical application with reference to the client and the server.
As shown in fig. 3, it is assumed that in the present practical application, the client a is in 8: 30 sends a request mode HTTP request to the server to obtain the target parameter X.
The structure of the HTTP request in the request mode is as follows:
when receiving the HTTP request of the request mode, the server side acquires the data of the target parameter X based on the payload X in the HTTP request, and then sends the HTTP response of the request mode to the client side A by taking the data of the target parameter X as response data.
The HTTP response structure of the request mode is as follows:
after receiving the HTTP response of the request mode, the client a, based on the traceID: 8: and 30, matching the payload in the HTTP response, wherein the traceID corresponding to the X: 8: 30, and based on the payload X processes the traceID: 8: 30 HTTP request.
After that, assume client a is at 9:00 sends HTTP request in long polling mode to the server to obtain response data triggered by the service event Y.
The HTTP request structure of the long polling mode is as follows:
when receiving the HTTP request in the long polling mode, the server establishes a connection channel in the long polling mode with the client a, and connects the connection channel with the deviceID: and suspending after A is associated. Then, the server follows and/or processes the service event Y based on the event and payload in the HTTP request, and waits for acquiring the service event Y to trigger the traceID: 9:00 response data.
Assume that a traffic event Y triggers a traceID: before 9:00 response data, client a responds at 9:10, sending a push-mode HTTP request to the server to obtain a traceID triggered by a service event Z: 9:10 response data.
The structure of the HTTP request in push mode is as follows:
when receiving an HTTP request in a push mode, the server returns a null response 200 OK in a form to the client A, and follows and/or processes a service event Z based on related data of event Z and payload Z in the HTTP request to obtain a traceID triggered by the service event Y: 9:10, response data.
After the service end finishes processing the service event Y, obtaining a traceID triggered by the service event Y: 9:00, based on deviceID: a finds a suspended connection channel, and sends an HTTP response of the long polling mode to the client A, wherein the HTTP response of the long polling mode not only carries response data of the HTTP request of the long polling mode, but also carries response data of the HTTP request of the push mode.
The HTTP response structure of the long polling mode is as follows:
after receiving the HTTP response of the long polling mode, the client A sends a new round of HTTP request of the long polling mode to the server; on the other hand, based on the traceID in the HTTP response 9:00, determining that the response data payload: Y corresponds to the traceID: 9:00, and responding to the response data payload: Y to track id: 9:00, and based on the traceID in the HTTP response, 9: and 10, determining that the response data payload Z corresponds to the traceID of 9:10, and responding to the response data payload, Z, to track ID, 9:10 HTTP request is processed.
The above practical application is only used for exemplarily describing the interaction method of the present embodiment, and does not limit the protection scope of the present specification. As another feasible scheme, after the server obtains the response data payload of the HTTP request in push mode, if the response data payload of the HTTP request in long polling mode is not obtained, the server may first use the deviceID: and the connection channel of the client A independently sends an HTTP response of the long polling mode to the client A, and the HTTP response carries response data payload of the HTTP request of the push mode. After receiving the response data, the client a may initiate a new round of HTTP request in the long polling mode to the server, and the server returns a response data payload: Y to the client a based on the new round of HTTP request in the long polling mode.
In another aspect, an embodiment of the present specification further provides a client device, as shown in fig. 4, including:
the request sending module 41 is configured to send a first HTTP request in an interactive manner to the server, where the first HTTP request carries information of the interactive manner, an identifier of the first HTTP request, and information for determining response data of the first HTTP request;
the response receiving module 42 is configured to receive an HTTP response sent by the server, where the HTTP response carries response data of the first HTTP request and an identifier of the first HTTP request;
the processing module 43 processes the first HTTP request according to the response data of the first HTTP request in the HTTP response and the identifier of the first HTTP request.
Obviously, the client device of the present embodiment is an execution subject of the interaction method applied to the client provided in the foregoing description. Therefore, the technical effect that can be achieved by the interaction method can also be achieved by the client device of the embodiment.
Specifically, the response data of the first HTTP request in the HTTP response and the identifier of the first HTTP request have an association relationship;
the processing module 43 of this embodiment matches the first HTTP request according to the identifier of the first HTTP request in the HTTP response, and processes the matched first HTTP request according to the response data associated with the identifier of the first HTTP request in the HTTP response.
Optionally, the interaction mode includes one of a request mode, a long polling mode, and a push mode.
If the HTTP response is sent by the server using the connection channel in the long polling mode, the sending module 41 sends a second HTTP request in the long polling mode to the server when receiving the HTTP response, so that the service ticket returns response data based on the second HTTP request.
In addition, an embodiment of this specification further provides a server device, as shown in fig. 5, including:
the request receiving module 51 is configured to receive a first HTTP request of an interactive mode initiated by a client, where the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request, and information for determining response data of the first HTTP request;
the response sending module 52 sends an HTTP response to the client according to the information of the interaction manner in the first HTTP request and the information of the response data determining the first HTTP request, where the HTTP response carries the identifier of the first HTTP request and the response data of the first HTTP request.
Obviously, the server device of this embodiment is an execution subject of the interaction method applied to the server provided in the foregoing description. Therefore, the technical effect that can be achieved by the interaction method can be achieved by the server device of the embodiment as well.
Specifically, in this embodiment, the response sending module 52 is specifically configured to:
determining the interactive mode of the first HTTP request according to the information of the interactive mode in the first HTTP request; obtaining response data according to the information for determining the response data of the first HTTP request in the first HTTP request; and sending an HTTP response carrying the response data to the client according to the determined interaction mode.
Optionally, the interaction mode includes one of a request mode, a push mode and a long polling mode.
When the interaction mode is a request mode, the response sending module 52 sends an HTTP response carrying the response data to the client according to the request mode, including: and sending the HTTP response of the request mode to the client according to a question-and-answer mechanism of the HTTP response.
When the interaction mode is a long polling mode, the first HTTP request further carries an identifier of the client; the response sending module 52 sends an HTTP response carrying the response data to the client according to the long polling mode, including: when the first HTTP request is received, establishing and suspending a connection channel of a long polling mode of the client, and associating the connection channel with the identifier of the client; when the response data is obtained, matching a suspended connection channel according to the identification of the client; and sending the HTTP response of the long polling mode to the client by using the matched connection channel.
When the interaction mode is the push mode, the response sending module 52 sends an HTTP response carrying the response data to the client according to the long polling mode, including: and when the response data is obtained and a connection channel of the long polling mode with the client is established based on other HTTP requests, sending an HTTP response of the long polling mode to the client by using the connection channel.
Optionally, the information for determining the response data of the first HTTP request includes information for triggering a service event of the response data;
the response sending module 52 obtains response data according to the information in the first HTTP request that determines the response data of the first HTTP request, and includes:
determining a service event according to the information of the service event triggering the response data in the first HTTP request;
obtaining response data triggered by the traffic event.
In addition, an embodiment of the present specification further provides a client device, as shown in fig. 6, including:
at least one processor 601, memory 602, at least one network interface 604, and a user interface 603. The various components in terminal 600 are coupled together by a bus system 605. It is understood that the bus system 605 is used to enable communications among the components. The bus system 605 includes a power bus, a control bus, and a status signal bus in addition to a data bus. For clarity of illustration, however, the various buses are labeled as bus system 605 in fig. 6.
The user interface 603 may include, among other things, a display, a keyboard, or a pointing device (e.g., a mouse, trackball, touch pad, or touch screen, among others.
It will be appreciated that the memory 602 in the subject embodiment can be either volatile memory or nonvolatile memory, or can include both volatile and nonvolatile memory. The non-volatile Memory may be a Read-Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), or a flash Memory. Volatile Memory can be Random Access Memory (RAM), which acts as external cache Memory. By way of illustration and not limitation, many forms of RAM are available, such as Static random access memory (SRAM, Static RAM), Dynamic random access memory (DRAM, Dynamic RAM), Synchronous Dynamic random access memory (SDRAM, Synchronous DRAM), Double Data Rate Synchronous Dynamic random access memory (DDRSDRAM, Double Data Rate SDRAM), Enhanced Synchronous Dynamic random access memory (ESDRAM, Enhanced SDRAM), Synchronous link Dynamic random access memory (SLDRAM, Synchronous DRAM), and Direct memory bus random access memory (DRRAM, Direct RAM). The memory 602 of the systems and methods described in this specification embodiments is intended to comprise, without being limited to, these and any other suitable types of memory.
In some embodiments, memory 602 stores the following elements, executable modules or data structures, or a subset thereof, or an expanded set thereof: an operating system 6021 and application programs 6022.
The operating system 6021 includes various system programs, such as a framework layer, a core library layer, a driver layer, and the like, and is used for implementing various basic services and processing hardware-based tasks. The application program 6022 includes various application programs such as a Media Player (Media Player), a Browser (Browser), and the like, and is used to implement various application services. A program that implements the methods of the embodiments of the present description may be included in the application program 6022.
In this specification embodiment, the client device 600 further includes: a computer program stored on a memory 602 and executable on a processor 601, the computer program when executed by the processor 601 performing the steps of:
sending a first HTTP request of an interactive mode to a server, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
receiving an HTTP response sent by a server, wherein the HTTP response carries response data of the first HTTP request and an identifier of the first HTTP request;
and processing the first HTTP request according to the response data of the first HTTP request in the HTTP response and the identification of the first HTTP request.
Optionally, the response data of the first HTTP request in the HTTP response and the identifier of the first HTTP request have an association relationship;
the computer program is executed by the processor to process the first HTTP request according to the response data of the first HTTP request and the identification of the first HTTP request in the HTTP response, and further realize the following steps:
processing the first HTTP request according to response data of the first HTTP request and the identifier of the first HTTP request in the HTTP response, wherein the processing comprises the following steps:
matching the first HTTP request according to the identifier of the first HTTP request in the HTTP response;
and processing the matched first HTTP request according to response data associated with the identifier of the first HTTP request in the HTTP response.
Optionally, the interaction mode includes one of a request mode, a long polling mode, and a push mode.
Optionally, if the HTTP response is sent by the server using a connection channel in the long polling mode, when the computer program is executed by the processor, the following steps are further implemented:
and when the HTTP response is received, sending a second HTTP request in the long polling mode to the server side, and enabling the server side to return response data to the client side based on the second HTTP request.
In addition, an embodiment of the present specification further provides a server device, as shown in fig. 7, including
At least one processor 701, a memory 702, at least one network interface 704, and a user interface 703. The various components in the terminal 700 are coupled together by a bus system 705. It is understood that the bus system 705 is used to enable communications among the components. The bus system 705 includes a power bus, a control bus, and a status signal bus in addition to a data bus. But for clarity of illustration the various busses are labeled in figure 7 as the bus system 705.
The user interface 703 may include, among other things, a display, a keyboard, or a pointing device (e.g., a mouse, trackball, touch pad, or touch screen, among others.
It will be appreciated that the memory 702 in the embodiments of the specification can be either volatile memory or nonvolatile memory, or can include both volatile and nonvolatile memory. The non-volatile Memory may be a Read-Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), or a flash Memory. Volatile Memory can be Random Access Memory (RAM), which acts as external cache Memory. By way of illustration and not limitation, many forms of RAM are available, such as Static random access memory (SRAM, Static RAM), Dynamic random access memory (DRAM, Dynamic RAM), Synchronous Dynamic random access memory (SDRAM, Synchronous DRAM), Double Data Rate Synchronous Dynamic random access memory (DDRSDRAM, Double Data Rate SDRAM), Enhanced Synchronous Dynamic random access memory (ESDRAM, Enhanced SDRAM), Synchronous link Dynamic random access memory (SLDRAM, Synchronous DRAM), and Direct memory bus random access memory (DRRAM, Direct RAM). The memory 702 of the systems and methods described in this specification embodiments is intended to comprise, without being limited to, these and any other suitable types of memory.
In some embodiments, memory 702 stores the following elements, executable modules or data structures, or a subset thereof, or an expanded set thereof: an operating system 7021 and application programs 7022.
The operating system 7021 includes various system programs, such as a framework layer, a core library layer, a driver layer, and the like, for implementing various basic services and processing hardware-based tasks. The application 7022 includes various applications, such as a Media Player (Media Player), a Browser (Browser), and the like, for implementing various application services. Programs that implement methods according to embodiments of the present description may be included in application 7022.
In this embodiment, the server device 700 further includes: a computer program stored on a memory 702 and executable on a processor 701, the computer program when executed by the processor 701 implementing the steps of:
receiving a first HTTP request of an interactive mode initiated by a client, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
and sending an HTTP response to the client according to the information of the interactive mode in the first HTTP request and the information for determining the response data of the first HTTP request, wherein the HTTP response carries the identifier of the first HTTP request and the response data of the first HTTP request.
Optionally, when the computer program is executed by the processor according to the information of the interaction manner in the first HTTP request and the information of the response data determining the first HTTP request, and sends an HTTP response to the client, the following steps are specifically implemented:
determining the interactive mode of the first HTTP request according to the information of the interactive mode in the first HTTP request;
obtaining response data according to the information for determining the response data of the first HTTP request in the first HTTP request;
and sending an HTTP response carrying the response data to the client according to the determined interaction mode.
Optionally, the interaction mode includes one of a request mode, a push mode and a long polling mode.
Optionally, when the interaction mode is a request mode, the computer program is executed by the processor to send an HTTP response to the client according to the determined interaction mode, and the following steps are specifically implemented:
and sending the HTTP response of the request mode to the client according to a question-and-answer mechanism of the HTTP response.
Optionally, when the interaction mode is a long polling mode, the first HTTP request further carries an identifier of the client; when the computer program is executed by the processor according to the determined interactive mode and sends an HTTP response to the client, the following steps are specifically realized:
when the first HTTP request is received, establishing and suspending a connection channel of a long polling mode of the client, and associating the connection channel with the identifier of the client;
when the response data is obtained, matching a suspended connection channel according to the identification of the client;
and sending the HTTP response of the long polling mode to the client by using the matched connection channel.
Optionally, when the interaction mode is the push mode, the computer program is executed by the processor to send an HTTP response carrying the response data to the client according to the determined interaction mode, and the following steps are specifically implemented:
and when the response data is obtained and a connection channel of the long polling mode with the client is established based on other HTTP requests, sending an HTTP response of the long polling mode to the client by using the connection channel.
Optionally, the information for determining the response data of the first HTTP request includes information for triggering a service event of the response data;
when the computer program is executed by the processor according to the information in the first HTTP request that determines the response data of the first HTTP request, and obtains the response data, the following steps are specifically implemented:
determining a service event according to the information of the service event triggering the response data in the first HTTP request;
obtaining response data triggered by the traffic event. Furthermore, an embodiment of the present description also provides a computer-readable storage medium having a computer program stored thereon, which when executed by a processor, implements the steps of:
sending a first HTTP request of an interactive mode to a server, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
receiving an HTTP response sent by a server, wherein the HTTP response carries response data of the first HTTP request and an identifier of the first HTTP request;
and processing the first HTTP request according to the response data of the first HTTP request in the HTTP response and the identification of the first HTTP request.
Optionally, the response data of the first HTTP request in the HTTP response and the identifier of the first HTTP request have an association relationship;
the computer program is executed by the processor to process the first HTTP request according to the response data of the first HTTP request and the identification of the first HTTP request in the HTTP response, and further realize the following steps:
processing the first HTTP request according to response data of the first HTTP request and the identifier of the first HTTP request in the HTTP response, wherein the processing comprises the following steps:
matching the first HTTP request according to the identifier of the first HTTP request in the HTTP response;
and processing the matched first HTTP request according to response data associated with the identifier of the first HTTP request in the HTTP response.
Optionally, the interaction mode includes one of a request mode, a long polling mode, and a push mode.
Optionally, if the HTTP response is sent by the server using a connection channel in the long polling mode, when the computer program is executed by the processor, the following steps are further implemented:
and when the HTTP response is received, sending a second HTTP request in the long polling mode to the server side, and enabling the server side to return response data to the client side based on the second HTTP request.
Furthermore, an embodiment of the present description also provides a computer-readable storage medium having a computer program stored thereon, which when executed by a processor, implements the steps of:
receiving a first HTTP request of an interactive mode initiated by a client, wherein the first HTTP request carries information of the interactive mode, an identifier of the first HTTP request and information for determining response data of the first HTTP request;
and sending an HTTP response to the client according to the information of the interactive mode in the first HTTP request and the information for determining the response data of the first HTTP request, wherein the HTTP response carries the identifier of the first HTTP request and the response data of the first HTTP request.
Optionally, when the computer program is executed by the processor according to the information of the interaction manner in the first HTTP request and the information of the response data determining the first HTTP request, and sends an HTTP response to the client, the following steps are specifically implemented:
determining the interactive mode of the first HTTP request according to the information of the interactive mode in the first HTTP request;
obtaining response data according to the information for determining the response data of the first HTTP request in the first HTTP request;
and sending an HTTP response carrying the response data to the client according to the determined interaction mode.
Optionally, the interaction mode includes one of a request mode, a push mode and a long polling mode.
Optionally, when the interaction mode is a request mode, the computer program is executed by the processor to send an HTTP response carrying the response data to the client according to the determined interaction mode, and the following steps are specifically implemented:
and sending the HTTP response of the request mode to the client according to a question-and-answer mechanism of the HTTP response.
Optionally, when the interaction mode is a long polling mode, the first HTTP request further carries an identifier of the client; when the computer program is executed by the processor according to the determined interactive mode and sends an HTTP response carrying the response data to the client, the following steps are specifically realized:
when the first HTTP request is received, establishing and suspending a connection channel of a long polling mode of the client, and associating the connection channel with the identifier of the client;
when the response data is obtained, matching a suspended connection channel according to the identification of the client;
and sending the HTTP response of the long polling mode to the client by using the matched connection channel.
Optionally, when the interaction mode is the push mode, the computer program is executed by the processor to send an HTTP response carrying the response data to the client according to the determined interaction mode, and the following steps are specifically implemented:
and when the response data is obtained and a connection channel of the long polling mode with the client is established based on other HTTP requests, sending an HTTP response of the long polling mode to the client by using the connection channel.
Optionally, the information for determining the response data of the first HTTP request includes information for triggering a service event of the response data;
when the computer program is executed by the processor according to the information in the first HTTP request that determines the response data of the first HTTP request, and obtains the response data, the following steps are specifically implemented:
determining a service event according to the information of the service event triggering the response data in the first HTTP request;
obtaining response data triggered by the traffic event.
As will be appreciated by one skilled in the art, embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, the description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the description 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.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The above description is only an example of the present specification, and is not intended to limit the present specification. Various modifications and alterations to this description will become apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present specification should be included in the scope of the claims of the present specification.