CN112583934B - Data communication method, apparatus and computer-readable storage medium - Google Patents

Data communication method, apparatus and computer-readable storage medium Download PDF

Info

Publication number
CN112583934B
CN112583934B CN202011587640.9A CN202011587640A CN112583934B CN 112583934 B CN112583934 B CN 112583934B CN 202011587640 A CN202011587640 A CN 202011587640A CN 112583934 B CN112583934 B CN 112583934B
Authority
CN
China
Prior art keywords
protocol
layer
http protocol
server
http
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011587640.9A
Other languages
Chinese (zh)
Other versions
CN112583934A (en
Inventor
李林林
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Sangfor Technologies Co Ltd
Original Assignee
Sangfor Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Sangfor Technologies Co Ltd filed Critical Sangfor Technologies Co Ltd
Priority to CN202011587640.9A priority Critical patent/CN112583934B/en
Publication of CN112583934A publication Critical patent/CN112583934A/en
Application granted granted Critical
Publication of CN112583934B publication Critical patent/CN112583934B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/18Multiprotocol handlers, e.g. single devices capable of handling multiple protocols

Abstract

The invention discloses a data communication method, a device and a computer readable storage medium, wherein the method comprises the steps of receiving a data request initiated by a client; and performing connection handshake with the server through the protocol negotiation layer to determine an HTTP (hyper text transport protocol) protocol communicated with the server, and establishing connection with the server, so that when the client communicates with a plurality of servers, the communication protocol of each server does not need to be acquired in advance, and the communication between the client and the server with any communication protocol can be realized based on the protocol negotiation layer of the gateway equipment.

Description

Data communication method, apparatus and computer-readable storage medium
Technical Field
The present invention relates to the field of data communication, and in particular, to a data communication method, device and computer-readable storage medium.
Background
With the rise of the internet industry, data communication protocols, such as the first version (HTTP 1. X) of the hypertext transfer protocol and the second version (HTTP 2) of the hypertext transfer protocol, are gradually increased, and many existing devices use both the HTTP1.X protocol and the HTTP2 protocol, so that a communication problem occurs that a communication protocol used by a server and a client is inconsistent during data communication, resulting in data communication failure.
Disclosure of Invention
The invention provides a data communication method, data communication equipment and a computer readable storage medium, and aims to solve the technical problem that data communication fails due to the fact that communication protocols of a server and a client are inconsistent at present.
In order to achieve the above object, the present invention provides a data communication method, which is applied to a gateway device, where the gateway device includes a first HTTP protocol layer, a second HTTP protocol layer, and a protocol negotiation layer, and the method includes:
receiving a data request initiated by a client;
performing connection handshake with a server through the protocol negotiation layer to determine an HTTP (hyper text transport protocol) protocol communicated with the server, and establishing connection with the server;
if the protocol negotiation result is that the data communication protocol with the server is the first HTTP protocol, sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the server, and sending a response returned by the server to the client through the first HTTP protocol layer;
and if the protocol negotiation result is that the data communication protocol with the server is the second HTTP, sending the data request of the second HTTP output by the second HTTP protocol layer to the server, and sending a response returned by the server to the client through the second HTTP protocol layer.
Preferably, the receiving a data request initiated by a client includes:
receiving a data request of a first HTTP protocol sent by the client through the first HTTP protocol layer;
correspondingly, the sending the data request of the second HTTP protocol output by the second HTTP protocol layer to the server includes:
sending a data request of a first HTTP protocol to the second HTTP protocol layer through the first HTTP protocol layer;
converting the data request of the first HTTP protocol into a data request of a second HTTP protocol based on the second HTTP protocol layer;
sending the data request of the second HTTP protocol to the server;
correspondingly, the sending the response returned by the server to the client through the second HTTP protocol layer includes:
receiving a response returned by the server through the second HTTP layer, and converting the response protocol returned by the server into the first HTTP protocol based on the second HTTP layer;
and the first HTTP protocol layer receives the response after the protocol conversion and sends the response to the client through the first HTTP protocol layer.
Preferably, the receiving, by the first HTTP protocol layer, the data request of the first HTTP protocol sent by the client includes:
when the data communication protocol of the client is a second HTTP protocol, receiving a data request of the second HTTP protocol sent by the client through the second HTTP protocol layer; performing protocol conversion on the received data request of the second HTTP based on the second HTTP protocol layer to obtain a data request of a first HTTP protocol, and sending the data request of the first HTTP protocol to the first HTTP protocol layer;
correspondingly, the sending a response to the client through the first HTTP protocol layer includes:
sending a response to the second HTTP protocol layer through the first HTTP protocol layer, and performing protocol conversion on the received response based on the second HTTP protocol layer;
and sending the response output by the second HTTP protocol layer to the client.
Preferably, before the data communication protocol of the client is the second HTTP protocol, the method further includes:
and performing connection handshake with the client through the protocol negotiation layer to determine a protocol for communication with the client, and establishing connection with the client.
Preferably, after the receiving a data request initiated by a client and before the performing a connection handshake with a server through the protocol agreement layer, the method further includes:
judging whether the application layer connection of the back-end server corresponding to the communication is established or not;
correspondingly, the performing a connection handshake with a server through the protocol negotiation layer to determine an HTTP protocol for communicating with the server and establish a connection with the server includes:
if the application layer connection is not established, performing connection handshake with the server through the protocol negotiation layer to determine an HTTP protocol communicated with the server, and establishing connection with the server;
correspondingly, after the determining whether the application layer connection of the backend server corresponding to the communication is established, the method further includes:
and if the application layer connection is established, performing application layer connection multiplexing.
In addition, to achieve the above object, the present invention provides another data communication method, which is applied to a gateway device including a first HTTP protocol layer and a second HTTP protocol layer, and includes:
receiving a data request initiated by a client through the first HTTP protocol layer;
sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the second HTTP protocol layer, and converting the data request output by the first HTTP protocol layer into the data request of the second HTTP protocol through the second HTTP protocol layer;
sending the data request output by the second HTTP protocol layer to a server;
receiving a response returned by the server through the second HTTP layer, and converting the response protocol into a first HTTP;
and the response of the first HTTP protocol output after the protocol conversion is carried out by the second HTTP protocol layer is sent to the first HTTP protocol layer, and the response is sent to the client through the first HTTP protocol layer.
Preferably, the receiving, by the first HTTP protocol layer, a data request initiated by a client includes:
when the data communication protocol of the client is a second HTTP protocol, receiving a data request of the second HTTP protocol sent by the client through the second HTTP protocol layer; performing protocol conversion on the received data request of the second HTTP protocol based on the second HTTP protocol layer to obtain a data request of a first HTTP protocol, and sending the data request of the first HTTP protocol to the first HTTP protocol layer;
correspondingly, the sending a response to the client through the first HTTP protocol layer includes:
sending the response output by the first HTTP protocol layer to the second HTTP protocol layer;
performing protocol conversion based on the second HTTP protocol layer;
and sending the response output after the protocol conversion of the second HTTP protocol layer to the client.
Preferably, the gateway device further comprises a protocol negotiation layer;
correspondingly, before the time when the data communication protocol of the client is the second HTTP protocol, the method further includes:
and carrying out protocol negotiation with the client through the protocol negotiation layer.
Preferably, the method further comprises:
performing connection handshake with a server through a protocol negotiation layer to determine an HTTP (hyper text transport protocol) protocol communicated with the server, and establishing connection with the server;
correspondingly, the sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the second HTTP protocol layer includes:
if the protocol negotiation result is that the data communication protocol with the server is a second HTTP protocol, sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the second HTTP protocol layer;
correspondingly, the method further comprises:
and if the protocol negotiation result is that the data communication protocol with the server is the first HTTP, sending the data request of the first HTTP output by the first HTTP protocol layer to the server, and sending a response returned by the server to the client through the first HTTP protocol layer.
Preferably, before the performing connection handshake with the server through the protocol negotiation layer to determine the HTTP protocol for communicating with the server and establishing connection with the server, the method further includes:
judging whether the application layer connection of the back-end server corresponding to the communication is established or not;
correspondingly, the performing a connection handshake with a server through the protocol negotiation layer to determine an HTTP protocol for communicating with the server and establish a connection with the server includes:
if the application layer connection is not established, performing connection handshake with the server through the protocol negotiation layer to determine an HTTP protocol communicated with the server, and establishing connection with the server;
correspondingly, after the determining whether the application layer connection of the backend server corresponding to the communication is established, the method further includes:
and if the application layer connection is established, performing application layer connection multiplexing.
Furthermore, in order to achieve the above object, the present invention also provides a gateway device, which includes a processor, a memory, and a data communication method program stored in the memory, and when the data communication method program is executed by the processor, the steps of the data communication method described above are implemented.
Furthermore, to achieve the above object, the present invention also provides a computer-readable storage medium having stored thereon a data communication method program which, when executed by a processor, implements the steps of the data communication method as described above.
Compared with the prior art, the invention discloses a data communication method, equipment and a computer readable storage medium, wherein the method comprises the steps of receiving a data request initiated by a client; performing connection handshake with a server through the protocol negotiation layer to determine an HTTP (hyper text transport protocol) protocol communicated with the server, and establishing connection with the server; if the protocol negotiation result is that the data communication protocol with the server is the first HTTP protocol, sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the server, and sending a response returned by the server to the client through the first HTTP protocol layer; if the protocol negotiation result is that the data communication protocol with the server is the second HTTP protocol, the data request of the second HTTP protocol output by the second HTTP protocol layer is sent to the server, and the response returned by the server is sent to the client through the second HTTP protocol layer, so that when the client needs to communicate with the servers with different HTTP protocols, the communication with the servers with different protocols can be realized through the method provided by the application, and the communication between the same client and the servers with different protocols can be realized at the same time.
Drawings
Fig. 1 is a schematic hardware configuration diagram of a gateway device according to embodiments of the present invention;
fig. 2 is a schematic flow chart of a first embodiment of the data communication method of the present invention;
fig. 3 is a flow chart illustrating a second embodiment of a data communication method of the present invention;
fig. 4 is a schematic flow chart of a third embodiment of the data communication method of the present invention;
fig. 5 is a flowchart illustrating a fourth embodiment of the data communication method according to the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The data communication method according to the embodiment of the present invention is applied to a gateway device, which may be a software gateway device or a hardware gateway device, and fig. 1 shows a schematic structural diagram of the hardware gateway device.
Referring to fig. 1, fig. 1 is a schematic diagram of a hardware structure of a gateway device according to embodiments of the present invention. In this embodiment of the present invention, the gateway device may include a processor 1001 (e.g., a Central Processing Unit, CPU), a communication bus 1002, an input port 1003, an output port 1004, and a memory 1005. The communication bus 1002 is used for realizing connection communication among the components; the input port 1003 is used for data input; the output port 1004 is used for data output, the memory 1005 may be a high-speed RAM memory, or a non-volatile memory (non-volatile memory), such as a magnetic disk memory, and the memory 1005 may optionally be a storage device independent of the processor 1001. Those skilled in the art will appreciate that the hardware configuration depicted in FIG. 1 is not intended to be limiting of the present invention, and may include more or less components than those shown, or some components in combination, or a different arrangement of components.
With continued reference to fig. 1, the memory 1005 of fig. 1, which is a readable storage medium, may include an operating system, a network communication module, an application program module, and a data communication method program. In fig. 1, the network communication module is mainly used for connecting to a server and performing data communication with the server; and the processor 1001 may call the data communication method program stored in the memory 1005 and perform the following operations:
receiving a data request initiated by a client;
performing connection handshake with a server through the protocol negotiation layer to determine an HTTP (hyper text transport protocol) protocol communicated with the server, and establishing connection with the server;
if the protocol negotiation result is that the data communication protocol with the server is the first HTTP protocol, sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the server, and sending a response returned by the server to the client through the first HTTP protocol layer;
and if the protocol negotiation result is that the data communication protocol with the server is the second HTTP, sending the data request of the second HTTP output by the second HTTP protocol layer to the server, and sending a response returned by the server to the client through the second HTTP protocol layer.
Further, the processor 1001 may be further configured to call a data communication method program stored in the memory 1005, and perform the following steps:
receiving a data request of a first HTTP protocol sent by the client through the first HTTP protocol layer;
correspondingly, the sending the data request of the second HTTP protocol output by the second HTTP protocol layer to the server includes:
sending a data request of a first HTTP protocol to the second HTTP protocol layer through the first HTTP protocol layer;
converting the data request of the first HTTP protocol into a data request of a second HTTP protocol based on the second HTTP protocol layer;
sending the data request of the second HTTP protocol to the server;
correspondingly, the sending the response returned by the server to the client through the second HTTP protocol layer includes:
receiving a response returned by the server through the second HTTP protocol layer, and converting the response protocol returned by the server into a first HTTP protocol based on the second HTTP protocol layer;
and the first HTTP protocol layer receives the response after the protocol conversion and sends the response to the client through the first HTTP protocol layer.
Further, the processor 1001 may be further configured to call a data communication method program stored in the memory 1005, and perform the following steps:
when the data communication protocol of the client is a second HTTP protocol, receiving a data request of the second HTTP protocol sent by the client through the second HTTP protocol layer; performing protocol conversion on the received data request of the second HTTP based on the second HTTP protocol layer to obtain a data request of a first HTTP protocol, and sending the data request of the first HTTP protocol to the first HTTP protocol layer;
correspondingly, the sending a response to the client through the first HTTP protocol layer includes:
sending a response to the second HTTP protocol layer through the first HTTP protocol layer, and performing protocol conversion on the received response based on the second HTTP protocol layer;
and sending the response output by the second HTTP protocol layer to the client.
Further, the processor 1001 may be further configured to call a data communication method program stored in the memory 1005, and perform the following steps:
and performing connection handshake with the client through the protocol negotiation layer to determine a protocol for communication with the client, and establishing connection with the client.
Further, the processor 1001 may be further configured to call a data communication method program stored in the memory 1005, and perform the following steps:
judging whether the application layer connection of the back-end server corresponding to the communication is established or not;
correspondingly, the performing a connection handshake with a server through the protocol negotiation layer to determine an HTTP protocol for communicating with the server and establish a connection with the server includes:
if the application layer connection is not established, performing connection handshake with the server through the protocol negotiation layer to determine an HTTP protocol communicated with the server, and establishing connection with the server.
Correspondingly, after the determining whether the application layer connection of the backend server corresponding to the communication is established, the method further includes:
and if the application layer connection is established, performing application layer connection multiplexing.
Based on the above-described structure, various embodiments of the data communication method of the present invention are proposed.
Referring to fig. 2, fig. 2 is a flow chart of a first embodiment of the data communication method of the present invention.
In this embodiment, the data communication method is applied to a gateway device, the gateway device includes a first HTTP protocol layer, a second HTTP protocol layer, and a protocol negotiation layer, optionally, the gateway device communicates with a client and a server only through the first HTTP protocol layer, the second HTTP protocol layer, and the protocol negotiation layer, optionally, the gateway device communicates through the first HTTP protocol layers, the second HTTP protocol layers, and the protocol negotiation layers, for example, the first HTTP protocol layer, the second HTTP protocol layer, and the protocol negotiation layer are all disposed on a client side, and the first HTTP protocol layer, the second HTTP protocol layer, and the protocol negotiation layer are also disposed on a server side, which is not limited in this embodiment, wherein the first HTTP protocol layer and the second HTTP protocol layer are two protocol layers supporting different protocols, such as HTTP1.X, HTTP2, and other HTTP protocol formats, and other protocol formats, and it is understood that, because the current data communication protocols are gradually increased, such as HTTP1.X (HTTP 1. X) and HTTP2 (HTTP 2) which support different protocols, even if many HTTP protocols are used in the problem of the communication technology of the current data communication protocol, the communication method is not based on the communication technology, the communication problem of the current data communication protocol, which is caused by the communication technology, even if many HTTP communication protocols, the communication protocol, the communication technology of the communication method is not used in the present invention, the communication method, also occurs. In the embodiment of the present application, the first HTTP protocol may be HTTP1.X or HTTP2, and the second HTTP protocol may be HTTP2 or HTTP1.X. This is not a limitation of the present application.
Specifically, the method comprises the following steps:
step S110: receiving a data request initiated by a client;
step S120: performing connection handshake with a server through the protocol negotiation layer to determine an HTTP (hyper text transport protocol) protocol communicated with the server, and establishing connection with the server;
specifically, in this embodiment, it should be noted that, a client and a server implement data communication based on a gateway device, the client sends a data communication request to the gateway device, then performs communication Negotiation with the server through the gateway device, and after determining a communication Protocol of the server through the communication Negotiation, establishes a connection with the server so that the server responds to the data request initiated by the client, where when receiving the data communication request initiated by the client, the client performs communication Negotiation with the server through a Protocol Negotiation Layer, where in this embodiment, the Protocol Negotiation Layer is used to perform Protocol Negotiation with the server, for example, a Protocol Negotiation function may be implemented through a Transport Layer Security Protocol (TLS) Layer or a Security Socket Layer (SSL) Layer that is extended by using an ALPN (Application Layer Protocol Negotiation), and the implementation of the Protocol Negotiation Layer may use the prior art, which is not limited in this Application.
Specifically, when the gateway device receives a data request initiated by a client, optionally, the gateway device parses the data request to determine whether the data request carries server information, such as server interface information, IP address information, server identification information, and the like, and if the data request carries the server information, the gateway device schedules the data request to a server corresponding to the data request (protocol negotiation may be performed after the server is determined, or protocol negotiation may be performed before the data request is obtained, and after the data request is received, a corresponding protocol layer is used for communicating with the server); optionally, when the data request does not carry server information, the data request may be dispatched to any server, for example, whether a server in an idle state and connected to the application layer exists at present is determined, if the server in the idle state and connected to the application layer exists, the data communication request is directly dispatched to the server in the idle state and connected to the application layer, and if the server in the idle state and connected to the application layer does not exist, negotiation is performed through the protocol negotiation layer.
It is easy to understand that, since many devices can use both the HTTP1 protocol and the HTTP2 protocol at present, and therefore the communication protocols used by the server and the client may be inconsistent, in this embodiment, in order to achieve successful communication even when the communication protocols of the server and the client are inconsistent, before dispatching the data request to the server, a protocol negotiation with the server needs to be performed through a protocol negotiation layer of the gateway device, for example, when the protocol negotiation layer is a TLS protocol negotiation layer, a connection handshake may be performed with the server through the TLS protocol negotiation layer, and during the connection handshake with the server through the TLS protocol negotiation layer, the HTTP protocol for communication with the server is determined through an ALPN protocol negotiation, and a connection is established with the server.
Further, in some embodiments, after the receiving a client-initiated data request and before the performing a connection handshake with a server through the protocol negotiation layer, the method further comprises:
judging whether the application layer connection of the back-end server corresponding to the communication is established or not;
correspondingly, the performing a connection handshake with a server through the protocol negotiation layer to determine an HTTP protocol for communicating with the server and establish a connection with the server includes:
if the application layer connection is not established, performing connection handshake with the server through the protocol negotiation layer to determine an HTTP protocol communicated with the server, and establishing connection with the server.
Correspondingly, after the determining whether the application layer connection of the backend server corresponding to the communication is established, the method further includes:
and if the application layer connection is established, performing application layer connection multiplexing.
Specifically, in this step, the current communication refers to a communication process corresponding to a data request initiated by a client, where a backend server refers to a server corresponding to a data request that needs to respond to the client, and where, as is easily understood, an HTTP protocol works in an application layer, in this embodiment, after receiving a data request initiated by a client, it is first determined whether a connection has been established between the application layer of the backend server corresponding to a data request initiated by a client and the client or a gateway device, and if an application layer connection has been established, the application layer connection multiplexing is directly performed, and no connection needs to be established with the server, so that the problem of low efficiency caused by frequent connection establishment with the server is solved, and further, if an application layer connection is not established, a handshake is performed with the server through the protocol negotiation layer to determine an HTTP protocol for communicating with the server, and a connection is established with the server.
Step S130: if the protocol negotiation result is that the data communication protocol with the server is the first HTTP protocol, sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the server, and sending a response returned by the server to the client through the first HTTP protocol layer;
specifically, when the protocol negotiation result is that the data communication protocol with the server is the first HTTP protocol, data communication is performed with the server through the first HTTP protocol layer of the gateway device, specifically, a data request initiated by the client and received by the gateway device is output through the first HTTP protocol layer, that is, the data request of the first HTTP protocol output by the first HTTP protocol layer is sent to the server, for example, when the request protocol of the data request initiated by the client is the first HTTP protocol, the data request of the first HTTP protocol sent by the client is received through the first HTTP protocol layer, and the data request of the first HTTP protocol sent by the client is sent to the server by the first HTTP protocol layer, and when the request protocol of the data request initiated by the client is the second HTTP protocol, the data request of the second HTTP protocol sent by the client is received through the second HTTP protocol layer, and the data request of the second HTTP protocol is converted into the data request of the first HTTP protocol, and sent to the first HTTP protocol layer, so that the data request of the second HTTP protocol sent by the client is sent to the server by the first HTTP protocol layer.
Further, after the data request of the first HTTP protocol output by the first HTTP protocol layer is transmitted to the server, since the data communication protocol of the server is the first HTTP protocol, the response returned by the server is also transmitted to the client through the first HTTP protocol layer, thereby realizing the freedom of the communication protocol between the server and the client.
Step S140: and if the protocol negotiation result is that the data communication protocol with the server is the second HTTP, sending the data request of the second HTTP output by the second HTTP protocol layer to the server, and sending a response returned by the server to the client through the second HTTP protocol layer.
Specifically, when the protocol negotiation result is that the data communication protocol with the server is the second HTTP protocol, the data communication is performed with the server through the second HTTP protocol layer of the gateway device, specifically, the data request initiated by the client and received by the gateway device is output through the second HTTP protocol layer, that is, the data request of the second HTTP protocol output by the second HTTP protocol layer is sent to the server, for example, when the client initiates the data communication protocol with the server, the data communication protocol is the second HTTP protocol layerWhen the request protocol of the data request is the second HTTP protocol, the data request of the second HTTP protocol sent by the client is received through the second HTTP protocol layer, the data request of the second HTTP protocol sent by the client is sent to the server through the second HTTP protocol layer, and when the request protocol of the data request initiated by the client is the second HTTP protocolAWhen HTTP protocol, throughAThe HTTP protocol layer receives the first data sent by the clientAData request of HTTP protocol, and the firstAThe data request of the HTTP protocol is converted into a data request of a second HTTP protocol and is sent to a second HTTP protocol layer, so that the data request of the first HTTP protocol sent by the client is sent to the server through the second HTTP protocol layer.
Furthermore, after the data request of the second HTTP protocol output by the second HTTP protocol layer is transmitted to the server, since the data communication protocol of the server is the second HTTP protocol, the response returned by the server is also transmitted to the client through the second HTTP protocol layer, thereby realizing a free communication protocol between the server and the client.
It should be noted that, in this embodiment, when the client needs to allocate the data request to another server, it is not necessary to determine in advance whether the communication protocols of the other servers to be allocated are consistent with the client, and based on the data request in this embodiment, no matter what the communication protocol of the backend server is, the data request can be communicated with the backend server through the gateway device, so that successful communication can be performed when the communication protocols of the server and the client are not consistent. In the technical scheme provided by the application, the gateway device further comprises a protocol negotiation layer, the communication protocol of each server does not need to be known in advance, when the servers are added, the communication protocol of the servers can be determined directly through protocol negotiation, the server capacity expansion performance is high, the number of the servers is increased conveniently, and therefore a plurality of servers can be added to process the data requests of the clients when the data requests of the clients are highly concurrent.
A second embodiment of the present invention is proposed based on the first embodiment shown in fig. 2 described above. As shown in fig. 3, fig. 3 is a flowchart illustrating a data communication method according to a second embodiment of the present invention.
In this embodiment, the receiving a data request initiated by a client includes:
step S1101: receiving a data request of a first HTTP protocol sent by the client through the first HTTP protocol layer;
in general, the current gateway device often supports a conventional HTTP protocol, for example, all support HTTP1.X, and the gateway device can perform multiple processing functions (for example, functions such as packet analysis and modification) on a packet of HTTP1.X, so that an embodiment of the present application provides a technical solution, in order to facilitate development on a conventional framework, regardless of whether a protocol type adopted by a backend server is a first HTTP protocol or a second HTTP protocol, a packet between the server and a client needs to pass through a first HTTP protocol layer, where the first HTTP protocol layer is used to implement a packet processing function, and the second HTTP protocol layer is mainly used to implement a protocol conversion function, so that most of data processing and analysis are concentrated on the first HTTP protocol layer, and the gateway device can support a newly added second HTTP protocol by adding the second HTTP protocol layer of the protocol conversion function. Therefore, the development efficiency can be improved through the scheme.
Those skilled in the art will readily understand that, in this solution, the first HTTP protocol is a conventional protocol, such as HTTP1.X protocol, and the second HTTP protocol is a protocol that needs to be newly supported, such as HTTP2 protocol or HTTP3 protocol, and the first HTTP protocol is HTTP1.X protocol and the second HTTP protocol is HTTP2 protocol as an example for illustration in the following description.
In this step, it should be noted that, because the gateway device supports the HTTP1.X protocol, that is, the first HTTP protocol, and can support various data processing on a data packet of the HTTP1.X protocol, in this embodiment, no matter the communication protocol format of the client and the server connected to the gateway device is the first HTTP protocol or the second HTTP protocol, in this embodiment, it is preferable to perform processing by using the first HTTP protocol layer, so as to facilitate subsequent protocol expansion, and it is further noted that the data request of the first HTTP protocol sent by the client includes a data request of the first HTTP protocol sent by the client based on the first HTTP protocol communication, and may also be a data request of the second HTTP protocol sent by the client based on the second HTTP protocol communication, and the data request of the first HTTP protocol is converted into a data request of the second HTTP protocol by using the second HTTP protocol layer of the gateway device.
In addition, for convenience of understanding, a specific implementation scheme is provided in this embodiment for receiving, by the first HTTP protocol layer, a data request of the first HTTP protocol sent by the client, which is specifically as follows:
when the data communication protocol of the client is a second HTTP protocol, receiving a data request of the second HTTP protocol sent by the client through the second HTTP protocol layer; performing protocol conversion on the received data request of the second HTTP based on the second HTTP protocol layer to obtain a data request of a first HTTP protocol, and sending the data request of the first HTTP protocol to the first HTTP protocol layer;
correspondingly, the sending a response to the client through the first HTTP protocol layer includes:
sending a response to the second HTTP protocol layer through the first HTTP protocol layer, and performing protocol conversion on the received response based on the second HTTP protocol layer;
and sending the response output by the second HTTP protocol layer to the client.
Specifically, when the data communication protocol of the client is the second HTTP protocol, the data request of the second HTTP protocol sent by the client needs to be received through the second HTTP protocol layer, and then the data request of the second HTTP protocol is converted into the data request of the first HTTP protocol by using the second HTTP protocol layer, so that the data request sent by the client is sent to the server through the first HTTP protocol layer.
Further, in order to support communication with a client of any protocol, in this embodiment, before the data communication protocol of the client is the second HTTP protocol, the method further includes the following steps:
and performing connection handshake with the client through the protocol negotiation layer to determine a protocol for communication with the client, and establishing connection with the client.
In this step, before connecting with the client, in order to achieve successful communication with the client, in this embodiment, a connection handshake is performed with the client through a protocol negotiation layer, for example, a connection handshake is performed with the client through a TLS protocol negotiation layer, and during the connection handshake with the client through the TLS protocol negotiation layer, an HTTP protocol for communication with the client is determined through an ALPN protocol negotiation, if a protocol negotiation result is that a data communication protocol with the client is a first HTTP protocol, communication is performed with the client through the first HTTP protocol layer, and if the protocol negotiation result is that the data communication protocol with the client is a second HTTP protocol, communication is performed with the client through the second HTTP protocol layer.
In addition, in the above solution, it is described that both the client and the server can perform protocol conversion through a second HTTP protocol layer, but there may be a plurality of second HTTP protocol layers, the client may perform protocol conversion through one second HTTP protocol layer, and the server may perform protocol conversion through another second HTTP protocol layer; similarly, there may be a plurality of protocol negotiation layers, the client may perform protocol conversion through one protocol negotiation layer, and the server may perform protocol conversion through another protocol negotiation layer. All of which are within the scope of the present application.
Correspondingly, the sending the data request of the second HTTP protocol output by the second HTTP protocol layer to the server includes:
step S1401: sending a data request of a first HTTP protocol to the second HTTP protocol layer through the first HTTP protocol layer;
step S1402: converting the data request of the first HTTP protocol into a data request of a second HTTP protocol based on the second HTTP protocol layer;
step S1403: sending the data request of the second HTTP protocol to the server;
specifically, when a data request initiated by a client is processed through a first HTTP protocol layer and a data communication protocol of a server is a second HTTP protocol, the first HTTP protocol layer is required to send the data request of the first HTTP protocol to the second HTTP protocol layer, and then the second HTTP protocol layer is required to convert the data request of the first HTTP protocol into the data request of the second HTTP protocol, that is, the first HTTP protocol layer is controlled to send an HTTP1.X data request to an HTTP2 protocol layer, so that the HTTP1.X data request is converted into an HTTP2 data request through the HTTP2 protocol layer, and the HTTP2 data request is sent to the server through the HTTP2 protocol layer, optionally, the HTTP2 protocol layer sends the HTTP2 data request to a protocol negotiation layer having a security protocol function, so that the HTTP2 data request is encrypted through the protocol negotiation layer, and the encrypted HTTP2 data request is sent to the server.
Correspondingly, the sending the response returned by the server to the client through the second HTTP protocol layer includes:
step S1404: receiving a response returned by the server through the second HTTP layer, and converting the response protocol returned by the server into the first HTTP protocol based on the second HTTP layer;
step S1405: and the first HTTP protocol layer receives the response after the protocol conversion and sends the response to the client through the first HTTP protocol layer.
Specifically, since the data communication protocol of the server is the second HTTP protocol, the response returned by the server needs to be received by the second HTTP protocol layer, and since the communication protocol of the client is the first HTTP protocol, the response returned by the server needs to be converted into the first HTTP protocol based on the second HTTP protocol layer, and the response returned by the server needs to be fed back to the client based on the first HTTP protocol layer, so that the communication can be successfully performed when the communication protocols between the client and the server are different.
In addition, it is noted that, because the gateway device supports the first HTTP protocol and can support any processing of the data packet of the first HTTP protocol, in this embodiment, the client and the server receive and forward the data packet through the first HTTP protocol layer regardless of any protocol, so that the gateway device can be expanded based on an existing gateway device framework during subsequent development, which is convenient for improving development efficiency.
Based on the above-described structure, various embodiments of the data communication method of the present invention are proposed.
Referring to fig. 4, fig. 4 is a flow chart of a data communication method according to a third embodiment of the present invention.
In this embodiment, the data communication method is applied to a gateway device, where the gateway device includes a first HTTP protocol layer and a second HTTP protocol layer, optionally, the gateway device communicates with a client and a server only through one first HTTP protocol layer and one second HTTP protocol layer, optionally, the gateway device communicates through multiple first HTTP protocol layers and multiple second HTTP protocol layers, for example, one first HTTP protocol layer and one second HTTP protocol layer are disposed on both the client and the server, which is not limited in this embodiment, where the first HTTP protocol layer and the second HTTP protocol layer are two protocol layers supporting different protocols, such as HTTP1.X, HTTP2 and other protocol formats, it can be understood that, as the number of data communication protocols currently used is gradually increased, such as a first version (HTTP 1. X) of a hypertext transfer protocol and a second version (HTTP 2) of the hypertext transfer protocol, many existing devices use the 2 protocols, even though the HTTP1.X protocols are used, the problem that the communication protocols used by the server and the client are consistent when the data communication, the data communication method fails to be based on the present invention.
Specifically, the method comprises the following steps:
s210: receiving a data request initiated by a client through the first HTTP protocol layer;
s220: sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the second HTTP protocol layer, and converting the data request output by the first HTTP protocol layer into the data request of the second HTTP protocol through the second HTTP protocol layer;
s230: sending the data request output by the second HTTP protocol layer to a server;
s240: receiving a response returned by the server through the second HTTP layer, and converting the response protocol into a first HTTP;
s250: and sending a response of the first HTTP protocol output after the second HTTP protocol layer performs protocol conversion to the first HTTP protocol layer, and sending the response to the client through the first HTTP protocol layer.
Through the scheme provided by the application, the client using the first HTTP protocol can communicate with the server using the second HTTP protocol. In addition, the scheme can also facilitate research and development on the existing gateway equipment, and the second HTTP protocol is additionally supported, so that the development efficiency can be improved.
The first HTTP protocol is HTTP1.X protocol, and the second HTTP protocol is HTTP2 protocol.
Since the gateway devices already support the first HTTP protocol (i.e., HTTP1.X protocol) and can support any processing of data packets of the first HTTP protocol, in this embodiment, the first HTTP protocol layer is used to receive data requests initiated by the client, and further, as more and more servers support protocols of a high protocol version (i.e., the second HTTP protocol), such as HTTP2, HTTP3, and other protocols, in this embodiment, the second HTTP protocol layer is used to receive response responses initiated by the server, and further, when the first HTTP protocol layer is used to receive data requests initiated by the client and the second HTTP protocol layer is used to receive response responses initiated by the server, in order to implement different successful communications, the intermediately transmitted data can be converted into protocol formats supported by the client and the server based on the second HTTP protocol layer and the first HTTP protocol, respectively.
In addition, for convenience of understanding, a specific implementation scheme for receiving a data request initiated by a client through the first HTTP protocol layer is provided in this embodiment, and the specific implementation scheme is as follows:
when the data communication protocol of the client is a second HTTP protocol, receiving a data request of the second HTTP protocol sent by the client through the second HTTP protocol layer; performing protocol conversion on the received data request of the second HTTP protocol based on the second HTTP protocol layer to obtain a data request of a first HTTP protocol, and sending the data request of the first HTTP protocol to the first HTTP protocol layer;
correspondingly, the sending a response to the client through the first HTTP protocol layer includes:
sending the response output by the first HTTP protocol layer to the second HTTP protocol layer;
performing protocol conversion based on the second HTTP protocol layer;
and sending the response output after the second HTTP protocol layer carries out protocol conversion to the client.
Specifically, when the data communication protocol of the client is the second HTTP protocol, the data request of the second HTTP protocol sent by the client needs to be received through the second HTTP protocol layer, and then the data request of the second HTTP protocol is converted into the data request of the first HTTP protocol by using the second HTTP protocol layer, so that the data request sent by the client is sent to the server through the first HTTP protocol layer.
Further, in order to support communication with a client of any protocol, in this embodiment, the gateway device further includes a protocol negotiation layer;
correspondingly, before the time when the data communication protocol of the client is the second HTTP protocol, the method further includes:
and carrying out protocol negotiation with the client through the protocol negotiation layer.
In this step, before connecting with the client, in order to implement successful communication with the client, in this embodiment, a connection handshake is performed with the client through the protocol negotiation layer, for example, the connection handshake is performed with the client through the TLS protocol negotiation layer, and during the connection handshake with the client through the TLS protocol negotiation layer, an HTTP protocol for communication with the client is determined through an ALPN protocol negotiation, if a result of the protocol negotiation is that a data communication protocol with the client is a first HTTP protocol, communication is performed with the client through the first HTTP protocol layer, and if a result of the protocol negotiation is that the data communication protocol with the client is a second HTTP protocol, communication is performed with the client through the second HTTP protocol layer.
Further, in order to support communication with a server of any protocol, in this embodiment, the method further includes:
performing connection handshake with a server through a protocol negotiation layer to determine an HTTP (hyper text transport protocol) protocol communicated with the server, and establishing connection with the server;
it should be noted that, in this embodiment, the client and the server implement data communication based on the gateway device, the gateway device performs communication negotiation with the server, and after determining a communication Protocol of the server through the communication negotiation, establishes a connection with the server so that the server responds to a data request initiated by the client, where when receiving the data communication request initiated by the client, the server performs communication negotiation with the Protocol negotiation Layer through the Protocol negotiation Layer, where in this embodiment, the Protocol negotiation Layer is used as a Protocol Layer that performs Protocol negotiation with the server and the client and encrypts and decrypts interactive data, for example, a TLS (Transport Layer Security Protocol) Protocol Layer or a SSL (Secure socket Layer) Protocol Layer.
It is easy to understand that, since many devices may use both the HTTP1 protocol and the HTTP2 protocol at present, the communication protocols used by the server and the client may be inconsistent, and therefore, in order to achieve successful communication even when the communication protocols of the server and the client are inconsistent in this embodiment, before dispatching the data request to the server, a connection handshake needs to be performed with the server through the protocol negotiation layer of the gateway device, for example, when the protocol negotiation layer is the TLS protocol negotiation layer, the connection handshake may be performed with the server through the TLS protocol negotiation layer, and during the connection handshake with the server through the TLS protocol negotiation layer, the HTTP protocol for communication with the server is negotiated through the ALPN protocol, and a connection is established with the server.
Correspondingly, the sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the second HTTP protocol layer includes:
if the protocol negotiation result is that the data communication protocol with the server is a second HTTP protocol, sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the second HTTP protocol layer;
specifically, when the protocol negotiation result is that the data communication protocol with the server is the second HTTP protocol, the data request initiated by the client received through the first HTTP protocol layer needs to be sent to the second HTTP protocol layer, so that the data request is forwarded to the server through the second HTTP protocol layer
Furthermore, after the data request of the second HTTP protocol output by the second HTTP protocol layer is transmitted to the server, since the data communication protocol of the server is the second HTTP protocol, the response returned by the server is also transmitted to the client through the second HTTP protocol layer, thereby realizing a free communication protocol between the server and the client.
Correspondingly, if the protocol negotiation result is that the data communication protocol with the server is the first HTTP protocol, the data request of the first HTTP protocol output by the first HTTP protocol layer is sent to the server, and the response returned by the server is sent to the client through the first HTTP protocol layer.
Specifically, when the protocol negotiation result is that the data communication protocol with the server is the first HTTP protocol, data communication is performed with the server through the first HTTP protocol layer of the gateway device, specifically, a data request initiated by the client and received by the gateway device is output through the first HTTP protocol layer, that is, the data request of the first HTTP protocol output by the first HTTP protocol layer is sent to the server, for example, when the request protocol of the data request initiated by the client is the first HTTP protocol, the data request of the first HTTP protocol sent by the client is received through the first HTTP protocol layer, and the data request of the first HTTP protocol sent by the client is sent to the server by the first HTTP protocol layer, and when the request protocol of the data request initiated by the client is the second HTTP protocol, the data request of the second HTTP protocol sent by the client is received through the second HTTP protocol layer, and the data request of the second HTTP protocol is converted into the data request of the first HTTP protocol, and sent to the first HTTP protocol layer, so that the data request of the second HTTP protocol sent by the client is sent to the server by the first HTTP protocol layer.
Furthermore, after the data request of the first HTTP protocol output by the first HTTP protocol layer is transmitted to the server, since the data communication protocol of the server is the first HTTP protocol, the response returned by the server is also transmitted to the client through the first HTTP protocol layer, thereby realizing a free communication protocol between the server and the client.
In addition, in some embodiments, before the performing, by the protocol negotiation layer, a connection handshake with a server to determine an HTTP protocol for communicating with the server and establish a connection with the server, the method further includes:
judging whether the application layer connection of the back-end server corresponding to the communication is established or not;
correspondingly, the performing a connection handshake with a server through the protocol negotiation layer to determine an HTTP protocol for communicating with the server and establish a connection with the server includes:
if the application layer connection is not established, performing connection handshake with the server through the protocol negotiation layer to determine an HTTP protocol communicated with the server, and establishing connection with the server;
correspondingly, after the determining whether the application layer connection of the backend server corresponding to the communication is established, the method further includes:
and if the application layer connection is established, performing application layer connection multiplexing.
Specifically, in this step, the current communication refers to a communication process corresponding to a data request initiated by a client, where a backend server refers to a server corresponding to a data request that needs to respond to the client, and where, as is easily understood, an HTTP protocol works in an application layer, in this embodiment, after receiving a data request initiated by a client, it is first determined whether a connection has been established between the application layer of the backend server corresponding to a data request initiated by a client and the client or a gateway device, and if an application layer connection has been established, the application layer connection multiplexing is directly performed without establishing a connection with another server, so as to alleviate the problem of low efficiency caused by frequent connection establishment with the server.
In addition, it is noted that, because the gateway device already supports the first HTTP protocol at present and can support any processing of the data packet of the first HTTP protocol, in this embodiment, no matter which protocol is used by the client and the server, the forwarding is received through the first HTTP protocol layer, so that the gateway device can communicate with the server supporting other communication protocols, and meanwhile, the existing gateway device framework can be used to perform corresponding extension, thereby reducing the research and development burden and improving the research and development efficiency.
Based on the above-described structure, various embodiments of the data communication method of the present invention are proposed.
Referring to fig. 5, fig. 5 is a flow chart illustrating a data communication method according to a fourth embodiment of the present invention.
In this embodiment, the data communication method is applied to a gateway device, the gateway device includes a first HTTP protocol layer, a second HTTP protocol layer and a protocol negotiation layer, optionally, the gateway device communicates with the client and the server only through a first HTTP protocol layer, a second HTTP protocol layer and a protocol negotiation layer, optionally, the gateway device communicates through a plurality of first HTTP protocol layers, a plurality of second HTTP protocol layers and a plurality of protocol negotiation layers, if a first HTTP protocol layer, a second HTTP protocol layer and a protocol negotiation layer are disposed on both the client side and the server side, the data communication efficiency is improved, which is not limited in this embodiment, wherein the first HTTP protocol layer and the second HTTP protocol layer are two protocol layers supporting different protocols, such as HTTP1.X, HTTP2 and other HTTP protocol formats, and the protocol version of the first HTTP protocol layer is lower than the protocol version of the second HTTP protocol layer, it is preferable, in this embodiment, the first HTTP protocol layer is defined as a protocol layer for transmitting HTTP1.X protocol format data or a protocol layer for converting HTTP2 format data into HTTP1 format data, and the second HTTP protocol layer is defined as a protocol layer for transmitting HTTP2 protocol format data or converting HTTP1.X format data into HTTP2 format data, it being understood that, as the number of data communication protocols, such as the first edition of hypertext transfer protocol (HTTP 1. X) and the second edition of hypertext transfer protocol (HTTP 2), increases, many existing devices use both HTTP1.X and HTTP2 protocols, therefore, the communication problem that data communication fails due to inconsistency of communication protocols used by the server and the client occurs during data communication, and the data communication method is provided based on the technical problem.
Specifically, the method comprises the following steps:
s310: receiving a data request initiated by a client;
s320: judging whether the application layer connection corresponding to the communication and the back-end server is established or not;
s330: if the application layer connection is not established, establishing the application layer connection with the server;
s340: and if the application layer connection is established, performing application layer connection multiplexing.
In the step, when a data communication request initiated by a client is received, whether a server which is connected with an application layer of a back-end server and is in an idle state exists at present is judged, if the server which is connected with the application layer of the back-end server and is in the idle state exists, the data communication request initiated by the client is directly responded through the connected server without establishing connection with other servers, and further the problem of low efficiency caused by frequent connection establishment between load balancing equipment and a server is solved, if the connected server does not exist, ALPN negotiation is carried out through a safety protocol transmission layer and a server which is not connected, and the application layer connection is established with the server based on a protocol negotiation result.
Further, in some embodiments, the step of upon receipt of a client-initiated data communication request comprises:
if the HTTP1.X data request initiated by the client is detected, the HTTP1.X data request initiated by the client is received through an HTTP1.X protocol layer; alternatively, the first and second liquid crystal display panels may be,
if an HTTP2 data request initiated by a client is detected, sending the HTTP2 data request to a security protocol transmission layer;
if the negotiation between the security protocol transmission layer and the client is detected to be successful, decrypting the HTTP2 data request through the security protocol transmission layer;
and sending the decrypted HTTP2 data request to an HTTP2 protocol unloading layer, converting the decrypted HTTP2 data request into an HTTP1.X data request through the HTTP2 protocol unloading layer, and sending the HTTP1.X data request to an HTTP1.X protocol layer.
In this step, it should be noted that the load balancing device in this embodiment may receive both an HTTP1.X data request initiated by the client and an HTTP2 data request initiated by the client.
Specifically, when detecting an HTTP1.X data request initiated by a client, receiving the HTTP1.X data request initiated by the client through an HTTP1.X protocol layer, when detecting an HTTP2 data request initiated by the client, sending the HTTP2 data request to a security protocol transport layer to negotiate an HTTP version between the client and a load balancing device through the security protocol transport layer, specifically, performing application layer protocol negotiation with the client through an ALPN (application layer protocol negotiation) of TLS1.3, if the client supports the HTTP2 request, and then performing SSL handshake phase with the client, the negotiation field sent in the HTTP handshake phase will have an 'h2', and when receiving feedback information of the HTTP support 2 by the security protocol transport layer, the security protocol transport layer will respond to the client with a 'h2' field, so that the load balancing device can establish a HTTP2 communication protocol connection with the client through the security protocol transport layer, further, after establishing the HTTP2 communication protocol connection with the client, decrypt the HTTP2 data request through the security protocol transport layer to obtain decrypted HTTP2 data request data, send the decrypted HTTP2 data request to an HTTP layer for offloading, and convert the HTTP2 data request into an HTTP1.x data request in an HTTP format, wherein the HTTP1.x data offload server is used for offloading.
In addition, in some embodiments, after the step of establishing the application layer connection or multiplexing the application layer connection with the server, the method further comprises the step of establishing the application layer connection or multiplexing the application layer connection
If the data communication protocol of the server is an HTTP2 protocol, controlling an HTTP1.X protocol layer to send an HTTP1.X data request to an HTTP2 protocol layer so as to convert the HTTP1.X data request into an HTTP2 data request through the HTTP2 protocol layer;
based on communication connection with a server, sending the HTTP2 data request to the server through an HTTP2 protocol layer, and receiving HTTP2 response data fed back by the server;
in this step, when the data communication protocol of the server is the HTTP2 protocol, the HTTP1.X protocol layer is controlled to send the HTTP1.X data request to the HTTP2 protocol layer, so as to convert the HTTP1.X data request into the HTTP2 data request through the HTTP2 protocol layer, and send the HTTP2 data request to the server through the HTTP2 protocol layer, optionally, the HTTP2 protocol layer sends the HTTP2 data request to the security protocol transmission layer, so as to encrypt the HTTP2 data request through the security protocol transmission layer, and send the encrypted HTTP2 data request to the server, when a response request sent by the server is detected, a response request sent by the server is received, so as to receive HTTP2 response data fed back by the server, further, the response request sent by the server is decrypted through the security protocol transmission layer, so as to obtain the HTTP2 response data fed back by the server.
Further, after the step of sending the HTTP2 data request to the server through the HTTP2 protocol layer based on the communication connection with the server and receiving the HTTP2 response data fed back by the server, the method further includes:
and sending the HTTP2 response data to the client based on the data communication protocol of the client.
After the HTTP2 response data fed back by the server is received, the HTTP2 response data is converted into response data which accords with the data communication protocol of the client according to the data communication protocol of the client, and the response data which accords with the data communication protocol of the client is sent to the client.
In addition, for convenience of understanding, this embodiment provides a specific implementation scheme for sending the HTTP2 response data to the client based on a data communication protocol of the client, which is specifically as follows:
decrypting the HTTP2 response data through a security protocol transmission layer to obtain the decrypted HTTP2 response data;
sending the decrypted HTTP2 response data to an HTTP2 protocol unloading layer so as to convert the decrypted HTTP2 response data into HTTP1.X response data through the HTTP2 protocol unloading layer;
and sending the HTTP1.X response data to an HTTP1.X protocol layer, and sending the HTTP1.X response data to a client based on a data communication protocol of the client.
In this embodiment, it should be noted that the HTTP2 protocol offload layer is a protocol layer for converting HTTP2 format data into HTTP1.X format data, and in this step, after receiving HTTP2 response data fed back by the server, the HTTP2 response data is decrypted by the security protocol transport layer to obtain the decrypted HTTP2 response data, and the decrypted HTTP2 response data is converted into HTTP1.X response data by the HTTP2 protocol offload layer, and finally, the HTTP1.X response data is sent to the client based on the data communication protocol of the client.
Specifically, the step of sending the http1.X response data to the client based on the data communication protocol of the client includes:
if the data communication protocol of the client is an HTTP1.X protocol, the HTTP1.X response data is sent to the client through an HTTP1.X protocol layer; alternatively, the first and second liquid crystal display panels may be,
if the data communication protocol of the client is the HTTP2 protocol, the HTTP1.X response data is sent to an HTTP2 protocol layer, so that the HTTP1.X response data is converted into HTTP2 response data through the HTTP2 protocol layer;
and sending the HTTP2 response data to a security protocol transmission layer so as to encrypt the HTTP2 response data through the security protocol transmission layer, and sending the encrypted HTTP2 response data to a client.
In this step, if the data communication protocol of the client is the http1.X protocol, the http1.X response data is directly sent to the client through the http1.X protocol layer.
If the data communication protocol of the client is the HTTP2 protocol, the HTTP1.X response data is sent to the HTTP2 protocol layer, so that the HTTP1.X response data is converted into the HTTP2 response data through the HTTP2 protocol layer, further, the HTTP2 response data is encrypted through the security protocol transmission layer, and the encrypted HTTP2 response data is sent to the client.
According to the scheme, the security protocol transmission layer decrypts the HTTP2 response data to obtain the decrypted HTTP2 response data; sending the decrypted HTTP2 response data to an HTTP2 protocol unloading layer so as to convert the decrypted HTTP2 response data into HTTP1.X response data through the HTTP2 protocol unloading layer; and sending the HTTP1.X response data to an HTTP1.X protocol layer, and sending the HTTP1.X response data to the client based on a data communication protocol of the client, thereby realizing that the load balancing equipment is connected with the client in an HTTP2 mode, and simultaneously realizing the problems of data rewriting and request scheduling when the load balancing equipment is connected with the server in an HTTP2 mode.
In addition, in some embodiments, after the step of establishing a communication connection with the server through a security protocol transport layer upon receiving the data communication request initiated by the client, the method further includes:
if the data communication protocol of the server is an HTTP1.X protocol, controlling an HTTP1.X protocol layer to send an HTTP1.X data request to a security protocol transmission layer so as to encrypt the HTTP1.X data request through the security protocol transmission layer;
sending the encrypted HTTP1.X data request to a server, and receiving HTTP1.X response data fed back by the server;
and sending the HTTP1.X response data to the client based on the data communication protocol of the client.
When the data communication protocol of the server is the HTTP1.X protocol, the HTTP1.X protocol layer is controlled to send the HTTP1.X data request to the security protocol transmission layer, the HTTP1.X data request is encrypted through the security protocol transmission layer, the encrypted HTTP1.X data request is sent to the server through the security protocol transmission layer, and finally HTTP1.X response data are sent to the client based on the data communication protocol of the client.
Specifically, the step of sending the http1.X response data to the client based on the data communication protocol of the client includes:
decrypting the HTTP1.X response data through a security protocol transport layer to obtain the decrypted HTTP1.X response data;
and sending the decrypted HTTP1.X response data to an HTTP1.X protocol layer, and sending the HTTP1.X response data to the client based on a data communication protocol of the client.
In the step, after receiving the http1.X response data fed back by the server, the http1.X response data is decrypted by the security protocol transport layer to obtain the decrypted http1.X response data, the decrypted http1.X response data is sent to the http1.X protocol layer, and finally, the http1.X response data is sent to the client based on the data communication protocol of the client.
Specifically, the step of sending http1.X response data to the client based on the data communication protocol of the client includes:
if the data communication protocol of the client is an HTTP1.X protocol, the decrypted HTTP1.X response data is sent to a security protocol transmission layer so as to obtain the encrypted HTTP1.X response data, and the encrypted HTTP1.X response data is sent to the client; alternatively, the first and second electrodes may be,
if the data communication protocol of the client is the HTTP2 protocol, sending the decrypted HTTP1.X response data to an HTTP2 protocol layer so as to convert the HTTP1.X response data into HTTP2 response data through the HTTP2 protocol layer;
and sending the HTTP2 response data to a security protocol transmission layer so as to encrypt the HTTP2 response data through the security protocol transmission layer, and sending the encrypted HTTP2 response data to a client.
It should be noted that, with the above solution, if the data communication protocol of the server is the http1.X protocol, the http1.X protocol layer is controlled to send the http1.X data request to the security protocol transport layer, so as to encrypt the http1.X data request by the security protocol transport layer; sending the encrypted HTTP1.X data request to a server, and receiving HTTP1.X response data fed back by the server; and based on a data communication protocol of the client, the HTTP1.X response data is sent to the client, so that the connection between the load balancing equipment and the client is HTTP, and when the connection between the load balancing equipment and the server is HTTP and HTTP2, the problems of data intercommunication, data rewriting and request scheduling are realized at the same time.
According to the scheme, when a data communication request initiated by a client is received, the communication connection is established with the server through a security protocol transmission layer; if the data communication protocol of the server is an HTTP2 protocol, controlling an HTTP1.X protocol layer to send an HTTP1.X data request to an HTTP2 protocol layer so as to convert the HTTP1.X data request into an HTTP2 data request through the HTTP2 protocol layer; sending the HTTP2 data request to a server through an HTTP2 protocol layer, and receiving HTTP2 response data fed back by the server; and based on the data communication protocol of the client, the HTTP2 response data is sent to the client, so that when the communication protocol of the server is inconsistent with the protocol request of the client, the HTTP1.X data request is converted into the HTTP2 data request through the HTTP2 protocol layer, and the response of the server is sent to the client according to the data communication protocol of the client, thereby realizing successful communication when the communication protocols of the server and the client are inconsistent.
In addition, an embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium stores a data communication method program, and when the data communication method program is executed by a processor, the data communication method program implements the steps of the data communication method, which are not described herein again.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrases "comprising a," "8230," "8230," or "comprising" does not exclude the presence of other like elements in a process, method, article, or system comprising the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention or the portions contributing to the prior art may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) as described above and includes several instructions for causing a terminal device to execute the method according to the embodiments of the present invention.
The above description is only for the preferred embodiment of the present invention and is not intended to limit the scope of the present invention, and all equivalent structures or flow transformations made by the present specification and drawings, or applied directly or indirectly to other related arts, are included in the scope of the present invention.

Claims (11)

1. A data communication method is applied to gateway equipment, the gateway equipment comprises a first HTTP protocol layer, a second HTTP protocol layer and a protocol agreement layer, and the protocol version of the first HTTP protocol layer is lower than that of the second HTTP protocol layer; the method comprises the following steps:
receiving a data request initiated by a client;
performing connection handshake with a server through the protocol negotiation layer to determine an HTTP protocol for communicating with the server, and establishing connection with the server, wherein the HTTP protocol comprises an HTTP1.X protocol, an HTTP2 protocol and an HTTP3 protocol, and the protocol negotiation layer comprises a TLS protocol layer or an SSL protocol layer of an application layer protocol negotiation extension;
if the protocol negotiation result is that the data communication protocol with the server is the first HTTP protocol, sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the server, and sending a response returned by the server to the client through the first HTTP protocol layer;
if the protocol negotiation result is that the data communication protocol with the server is the second HTTP protocol, sending the data request of the second HTTP protocol output by the second HTTP protocol layer to the server, and sending a response returned by the server to the client through the second HTTP protocol layer;
the first HTTP protocol layer is used for realizing a data packet processing function, and the second HTTP protocol layer is used for realizing a protocol conversion function;
the receiving of the data request initiated by the client includes:
receiving a data request of a first HTTP protocol sent by the client through the first HTTP protocol layer;
correspondingly, the sending the data request of the second HTTP protocol output by the second HTTP protocol layer to the server includes:
sending a data request of a first HTTP protocol to the second HTTP protocol layer through the first HTTP protocol layer;
converting the data request of the first HTTP protocol into a data request of a second HTTP protocol based on the second HTTP protocol layer;
sending the data request of the second HTTP protocol to the server;
correspondingly, the sending the response returned by the server to the client through the second HTTP protocol layer includes:
receiving a response returned by the server through the second HTTP protocol layer, and converting the response protocol returned by the server into a first HTTP protocol based on the second HTTP protocol layer;
and the first HTTP protocol layer receives the response after the protocol conversion and sends the response to the client through the first HTTP protocol layer.
2. The data communication method according to claim 1, wherein said receiving, by the first HTTP protocol layer, a data request of a first HTTP protocol sent by the client includes:
when the data communication protocol of the client is a second HTTP protocol, receiving a data request of the second HTTP protocol sent by the client through the second HTTP protocol layer; performing protocol conversion on the received data request of the second HTTP based on the second HTTP protocol layer to obtain a data request of a first HTTP protocol, and sending the data request of the first HTTP protocol to the first HTTP protocol layer;
correspondingly, the sending a response to the client through the first HTTP protocol layer includes:
sending a response to the second HTTP protocol layer through the first HTTP protocol layer, and performing protocol conversion on the received response based on the second HTTP protocol layer;
and sending the response output by the second HTTP protocol layer to the client.
3. The data communication method according to claim 2, further comprising, before the time when the data communication protocol of the client is the second HTTP protocol:
and performing connection handshake with the client through the protocol negotiation layer to determine a protocol for communication with the client, and establishing connection with the client.
4. The data communication method of any one of claims 1 to 3, wherein after the receiving a client-initiated data request and before the performing a connection handshake with a server through the protocol agreement layer, further comprising:
judging whether the application layer connection of the back-end server corresponding to the communication is established or not;
correspondingly, the performing a connection handshake with a server through the protocol negotiation layer to determine an HTTP protocol for communicating with the server and establish a connection with the server includes:
if the application layer connection is not established, performing connection handshake with the server through the protocol negotiation layer to determine an HTTP protocol communicated with the server, and establishing connection with the server;
correspondingly, after the determining whether the application layer connection of the backend server corresponding to the communication is established, the method further includes:
and if the application layer connection is established, performing application layer connection multiplexing.
5. A data communication method is applied to a gateway device, the gateway device comprises a first HTTP protocol layer and a second HTTP protocol layer, the first HTTP protocol layer is used for realizing a data packet processing function, the second HTTP protocol layer is used for realizing a protocol conversion function, and the protocol version of the first HTTP protocol layer is lower than that of the second HTTP protocol layer;
the method comprises the following steps:
receiving a data request initiated by a client through the first HTTP protocol layer;
sending a data request of a first HTTP protocol output by the first HTTP protocol layer to the second HTTP protocol layer, and converting the data request output by the first HTTP protocol layer into a data request of a second HTTP protocol through the second HTTP protocol layer, wherein the first HTTP protocol comprises an HTTP1.X protocol, and the second HTTP protocol comprises an HTTP2 protocol or an HTTP3 protocol;
sending the data request output by the second HTTP protocol layer to a server;
receiving a response returned by the server through the second HTTP layer, and converting the response protocol into a first HTTP;
and sending a response of the first HTTP protocol output after the second HTTP protocol layer performs protocol conversion to the first HTTP protocol layer, and sending the response to the client through the first HTTP protocol layer.
6. The data communication method of claim 5, wherein said receiving a client-initiated data request through said first HTTP protocol layer comprises:
when the data communication protocol of the client is a second HTTP protocol, receiving a data request of the second HTTP protocol sent by the client through the second HTTP protocol layer; performing protocol conversion on the received data request of the second HTTP protocol based on the second HTTP protocol layer to obtain a data request of a first HTTP protocol, and sending the data request of the first HTTP protocol to the first HTTP protocol layer;
correspondingly, the sending a response to the client through the first HTTP protocol layer includes:
sending the response output by the first HTTP protocol layer to the second HTTP protocol layer;
performing protocol conversion based on the second HTTP protocol layer;
and sending the response output after the second HTTP protocol layer carries out protocol conversion to the client.
7. The data communication method of claim 6, wherein the gateway device further comprises a protocol negotiation layer;
correspondingly, before the time when the data communication protocol of the client is the second HTTP protocol, the method further includes:
and carrying out protocol negotiation with the client through the protocol negotiation layer.
8. The data communication method according to any of claims 5 to 7, wherein the method further comprises:
performing connection handshake with a server through a protocol negotiation layer to determine an HTTP (hyper text transport protocol) protocol communicated with the server, and establishing connection with the server;
correspondingly, the sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the second HTTP protocol layer includes:
if the protocol negotiation result is that the data communication protocol with the server is a second HTTP protocol, sending the data request of the first HTTP protocol output by the first HTTP protocol layer to the second HTTP protocol layer;
accordingly, the method further comprises:
and if the protocol negotiation result is that the data communication protocol with the server is the first HTTP, sending the data request of the first HTTP output by the first HTTP protocol layer to the server, and sending a response returned by the server to the client through the first HTTP protocol layer.
9. The data communication method according to claim 8, wherein before the performing a connection handshake with a server through the protocol negotiation layer to determine an HTTP protocol for communicating with the server and establish a connection with the server, further comprising:
judging whether the application layer connection of the back-end server corresponding to the communication is established or not;
correspondingly, the performing a connection handshake with a server through the protocol negotiation layer to determine an HTTP protocol for communicating with the server and establish a connection with the server includes:
if the application layer connection is not established, performing connection handshake with the server through the protocol negotiation layer to determine an HTTP protocol communicated with the server, and establishing connection with the server;
correspondingly, after the determining whether the application layer connection of the backend server corresponding to the communication is established, the method further includes:
and if the application layer connection is established, performing application layer connection multiplexing.
10. A gateway device, characterized in that the gateway device comprises a processor, a memory and a data communication method program stored in the memory, which when executed by the processor, carries out the steps of the data communication method according to any one of claims 1 to 9.
11. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a data communication method program which, when executed by a processor, implements the steps of the data communication method according to any one of claims 1 to 9.
CN202011587640.9A 2020-12-28 2020-12-28 Data communication method, apparatus and computer-readable storage medium Active CN112583934B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011587640.9A CN112583934B (en) 2020-12-28 2020-12-28 Data communication method, apparatus and computer-readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011587640.9A CN112583934B (en) 2020-12-28 2020-12-28 Data communication method, apparatus and computer-readable storage medium

Publications (2)

Publication Number Publication Date
CN112583934A CN112583934A (en) 2021-03-30
CN112583934B true CN112583934B (en) 2023-03-31

Family

ID=75143823

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011587640.9A Active CN112583934B (en) 2020-12-28 2020-12-28 Data communication method, apparatus and computer-readable storage medium

Country Status (1)

Country Link
CN (1) CN112583934B (en)

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109150788A (en) * 2017-06-13 2019-01-04 中兴通讯股份有限公司 Control method, apparatus, gateway and the storage medium of network data transmission
CN109729040B (en) * 2017-10-27 2022-04-29 伊姆西Ip控股有限责任公司 Method, apparatus and computer readable medium for selection of a protocol
CN110677405B (en) * 2019-09-26 2021-10-26 北京金山云网络技术有限公司 Data processing method and device, electronic equipment and storage medium
CN110995647A (en) * 2019-10-24 2020-04-10 珠海格力电器股份有限公司 Protocol conversion method, device, equipment, storage medium and system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
从应用层协议协商机制看,是否应该选择支持HTTP/2的CDN;又拍云;《https://zhuanlan.zhihu.com/p/29260981?from_voters_page=true》;20170922;全文 *

Also Published As

Publication number Publication date
CN112583934A (en) 2021-03-30

Similar Documents

Publication Publication Date Title
EP3352431B1 (en) Network load balance processing system, method, and apparatus
US9549096B2 (en) Image processing system, relay server, and program for relaying communications
WO2022135369A1 (en) Printing method and apparatus, and electronic device
WO2013170177A1 (en) System and method for reducing a call establishment time
US10367894B2 (en) Information processing apparatus, method for controlling the same, non-transitory computer-readable storage medium, and information processing system
CN110875914B (en) Method and device for transmitting messages based on shared session link
CN113438256B (en) Data transmission method, system and proxy server based on double-layer SSL
US8239548B2 (en) Endpoint discriminator in network transport protocol startup packets
CN111786989B (en) Communication processing method and device and electronic equipment
CN112583934B (en) Data communication method, apparatus and computer-readable storage medium
CN111787048B (en) Connection method of terminal equipment, scheduling server and Internet of things system
CN111131470B (en) Terminal device, data processing method thereof and data processing system
CN108900584B (en) Data transmission method and system for content distribution network
JP2001195330A (en) Gateway server and contents acquisition method
CN112202780B (en) Data transmission method, device, equipment and medium based on double sockets
CN111092888B (en) Method, device, equipment and storage medium for data simultaneous intercommunication
WO2008050585A1 (en) Two-way communication system, server apparatus, relay apparatus, two-way communication method and program
CN102857504B (en) Network optimized approach and device
CN102325187A (en) System and method for integrating multiple function services
CN113542324A (en) Message pushing method and device
JP6916529B2 (en) Device server and device server control method
JP2001230812A (en) Network connector off-loading communication start processing and method using it
CN114301968B (en) Access method, system, equipment and storage medium of server
US10567516B2 (en) Sharing local network resources with a remote VDI instance
CN114640447A (en) Data packet processing method, intelligent network card and storage medium

Legal Events

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