Communication method, device, equipment and medium

By introducing serialization processing and protocol header identification mechanisms between the client and the server, the problem of restricted communication protocols in the prior art is solved, and flexible communication and efficient data transmission between the client and the server are realized.

CN119865536APending Publication Date: 2025-04-22BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411889558.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-20
Publication Date
2025-04-22

AI Technical Summary

Technical Problem

In the prior art, the client or server only supports the HTTP/1.1 communication protocol, resulting in limited communication flexibility between the client and the server, and it is impossible to communicate with the server or client that supports more efficient communication protocols.

Method used

By introducing serialization processing and protocol header identification mechanisms between the client and the server, the client serializes the target data and encapsulates it into a message body, including protocol header fields for identifying the serialization method and protocol version. The server identifies the communication protocol based on these fields and performs corresponding processing.

Benefits of technology

It realizes flexible communication between the client and the server, allows dynamic selection and identification of communication protocols, avoids the problem of communication limitations, and improves system compatibility and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119865536A_ABST
    Figure CN119865536A_ABST
Patent Text Reader

Abstract

The invention relates to a communication method and device, equipment and a medium. According to the invention, the target data to be sent to the server is serialized through the client to obtain the first binary data, and the first binary data is packaged to obtain the first message body. Furthermore, the client side sends request information to the server side by adopting a target communication protocol, the request information comprises a first protocol header and a first message body, and the first protocol header comprises a first field used for identifying a serialization mode and a second field used for identifying a protocol version. And after receiving the request information, the server identifies the target communication protocol according to the first field and the second field, and sends the feedback information to the client by adopting the target communication protocol, thereby realizing communication between the client and the server. In other words, under the condition that compatibility is not affected, the client side can dynamically select the communication protocol, and the server side can dynamically identify the communication protocol. And the flexibility of communication between the client and the server is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computers, and in particular to a communication method, device, equipment and medium. Background Art

[0002] With the development of cloud computing technology, clients can be deployed on multiple hosts, and servers can also be deployed on multiple hosts. The client and server can communicate with each other. Specifically, the client and server can use a fixed communication protocol such as the 1.1 version of the Hypertext Transfer Protocol (HTTP), namely HTTP / 1.1, to communicate. However, the transmission efficiency of HTTP / 1.1 is not high, so more efficient communication protocols such as HTTP / 2 and Google Remote Procedure Call (gRPC) are proposed.

[0003] However, in the prior art, some clients or servers only support the communication protocol HTTP / 1.1, but not more efficient communication protocols such as HTTP / 2 and gRPC. Therefore, some clients can only communicate with fixed servers, and some servers can only communicate with fixed clients, which results in limited communication between some clients or servers. Summary of the invention

[0004] In order to solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a communication method, an apparatus, a device and a medium, which improve the flexibility of communication between a client and a server.

[0005] In a first aspect, an embodiment of the present disclosure provides a communication method, which is applied to a client and includes:

[0006] Serializing the target data to be sent to the server to obtain first binary data, and encapsulating the first binary data to obtain a first message body;

[0007] Using the target communication protocol to send a request message to the server, the request message includes a first protocol header and the first message body, the first protocol header includes a first field for identifying a serialization mode and a second field for identifying a protocol version, the first field and the second field are used to identify the target communication protocol;

[0008] receiving feedback information sent by the server using the target communication protocol, the feedback information including a second protocol header and a second message body, the second protocol header including the first field and the second field, and the second message body including second binary data;

[0009] According to the first field, the second binary data is parsed using a parser corresponding to the serialization method to obtain response data.

[0010] In a second aspect, an embodiment of the present disclosure provides a communication method, which is applied to a server, and the method includes:

[0011] Receive request information sent by a client, the request information including a first protocol header and a first message body, the first protocol header including a first field for identifying a serialization method and a second field for identifying a protocol version, the first message body including first binary data, the first binary data being a result obtained after the client serializes the target data using the serialization method;

[0012] Identify, according to the first field and the second field, a target communication protocol used by the client when sending the request information;

[0013] According to the first field, using a parser corresponding to the serialization method to parse the first binary data to obtain the target data;

[0014] generating response data according to the target data;

[0015] The response data is serialized in the serialization manner to obtain second binary data, and the second binary data is encapsulated to obtain a second message body;

[0016] Feedback information is sent to the client using the target communication protocol, where the feedback information includes a second protocol header and the second message body, and the second protocol header includes the first field and the second field.

[0017] In a third aspect, an embodiment of the present disclosure provides a communication device, which is configured on a client, and includes:

[0018] A serialization module, used for serializing the target data to be sent to the server to obtain first binary data;

[0019] An encapsulation module, used for encapsulating the first binary data to obtain a first message body;

[0020] A sending module, configured to send a request message to the server using the target communication protocol, wherein the request message includes a first protocol header and the first message body, wherein the first protocol header includes a first field for identifying a serialization mode and a second field for identifying a protocol version, and the first field and the second field are used to identify the target communication protocol;

[0021] A receiving module, configured to receive feedback information sent by the server using the target communication protocol, wherein the feedback information includes a second protocol header and a second message body, the second protocol header includes the first field and the second field, and the second message body includes second binary data;

[0022] A parsing module is used to parse the second binary data according to the first field using a parser corresponding to the serialization method to obtain response data.

[0023] In a fourth aspect, an embodiment of the present disclosure provides a communication device, which is configured at a server, and includes:

[0024] A receiving module, configured to receive request information sent by a client, wherein the request information includes a first protocol header and a first message body, wherein the first protocol header includes a first field for identifying a serialization method and a second field for identifying a protocol version, and the first message body includes first binary data, wherein the first binary data is a result obtained after the client serializes the target data using the serialization method;

[0025] an identification module, configured to identify, according to the first field and the second field, a target communication protocol used by the client when sending the request information;

[0026] a parsing module, configured to parse the first binary data according to the first field by using a parser corresponding to the serialization method to obtain the target data;

[0027] A generating module, used for generating response data according to the target data;

[0028] A serialization processing module, used for serializing the response data in the serialization manner to obtain second binary data, and encapsulating the second binary data to obtain a second message body;

[0029] A sending module is used to send feedback information to the client using the target communication protocol, wherein the feedback information includes a second protocol header and the second message body, and the second protocol header includes the first field and the second field.

[0030] In a fifth aspect, an embodiment of the present disclosure provides an electronic device, including:

[0031] Memory;

[0032] Processor; and

[0033] Computer programs;

[0034] The computer program is stored in the memory and is configured to be executed by the processor to implement the method as described in the first aspect or the second aspect.

[0035] In a sixth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to implement the method described in the first aspect or the second aspect.

[0036] In a seventh aspect, an embodiment of the present disclosure provides a computer program product, including a computer program, wherein the computer program implements the method described in the first aspect or the second aspect when executed by a processor.

[0037] The communication method, device, equipment and medium provided by the embodiment of the present disclosure serialize the target data to be sent to the server to obtain the first binary data through the client, and encapsulate the first binary data to obtain the first message body. Further, the client uses the target communication protocol to send a request message to the server, and the request message includes a first protocol header and a first message body. The first protocol header includes a first field for identifying the serialization method and a second field for identifying the protocol version. Among them, the first field and the second field can identify the target communication protocol used by the client, so that after receiving the request information, the server identifies the target communication protocol according to the first field and the second field, and uses the target communication protocol to send feedback information to the client, thereby realizing communication between the client and the server. In other words, without affecting compatibility, the client can dynamically select the communication protocol, and the server can dynamically identify the communication protocol. It avoids that some clients can only communicate with fixed servers, and some servers can only communicate with fixed clients, thereby improving the flexibility of communication between the client and the server. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0040] Figure 1 A flow chart of a communication method provided by an embodiment of the present disclosure;

[0041] Figure 2 A schematic diagram of an application scenario provided by an embodiment of the present disclosure;

[0042] Figure 3 A flow chart of a communication method provided by an embodiment of the present disclosure;

[0043] Figure 4 A schematic diagram of a frame structure provided in an embodiment of the present disclosure;

[0044] Figure 5 A flow chart of a communication method provided by an embodiment of the present disclosure;

[0045] Figure 6 A flow chart of a communication method provided by an embodiment of the present disclosure;

[0046] Figure 7 A schematic diagram of multiple bidirectional flows provided for an embodiment of the present disclosure;

[0047] Figure 8 A schematic diagram of the structure of a communication device provided in an embodiment of the present disclosure;

[0048] Fig. 9 A schematic diagram of the structure of a communication device provided in an embodiment of the present disclosure;

[0049] Fig.10 A schematic diagram of the structure of an electronic device embodiment provided by the present disclosure. DETAILED DESCRIPTION

[0050] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.

[0051] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.

[0052] Typically, the client can be deployed on multiple hosts, and the server can also be deployed on multiple hosts. The client and the server can communicate with each other. Specifically, the client and the server can use a fixed communication protocol such as the 1.1 version of the Hypertext Transfer Protocol (HTTP), namely HTTP / 1.1, to communicate. However, the transmission efficiency of HTTP / 1.1 is not high, so more efficient communication protocols such as HTTP / 2 and Google Remote Procedure Call (gRPC) are proposed. However, some clients or servers only support communication protocols such as HTTP / 1.1, but do not support more efficient communication protocols such as HTTP / 2 and gRPC. Therefore, some clients can only communicate with fixed servers, and some servers can only communicate with fixed clients, resulting in limited communication between some clients or servers. In response to this problem, the present disclosure provides a communication method, which is described below in conjunction with specific embodiments.

[0053] Figure 1 The communication method flow chart provided in the embodiment of the present disclosure. The method is applied to the client. The client can communicate with the server, and the client and the server are subsystems in the cloud native architecture. The method can be applied to Figure 2 The application scenario shown includes a client 21, a registration center 22 and a server 23. Specifically, the server 23 can support multiple communication protocols. For example, the server 23 supports communication protocols such as HTTP / 1.1, HTTP / 2, and gRPC. In addition, the server 23 can be deployed on multiple hosts or multiple machines. The server 23 can be registered in the registration center 22. For example, the server 23 sends registration information to the registration center 22. The registration information includes the service name corresponding to the server 23, the Internet Protocol (IP) addresses of the multiple hosts or multiple machines where the server 23 is deployed, one or more of the multiple communication protocols supported by the server 23, the port number corresponding to the server 23, and the functions provided by the server 23. The following is combined with Figure 2 The communication method described in the embodiment of the present disclosure is introduced. Figure 1 As shown, the specific steps of this method are as follows:

[0054] S101. Serialize target data to be sent to a server to obtain first binary data, and encapsulate the first binary data to obtain a first message body.

[0055] Before the client 21 initiates a request to the server 23, the client 21 can serialize the target data to be sent to obtain the first binary data. Specifically, if the target communication protocol determined by the client 21 is gRPC, the client 21 uses the data structure serialization and deserialization framework (Protocol Buffer, ProtoBuf) to serialize the target data to be sent, and generates data in ProtoBuf format, which is binary data, and the data in ProtoBuf format is the first binary data. Further, the client 21 encapsulates the first binary data to obtain a first message body, that is, the first message body includes the first binary data. If the target communication protocol determined by the client 21 is HTTP / 2, the client 21 uses the Javascript Object Notation (JSON) serialization method or other serialization methods other than ProtoBuf to serialize the target data to be sent to generate the first binary data. If the target communication protocol determined by the client 21 is HTTP / 1.1, the client 21 can use JSON serialization or other serialization methods other than JSON and ProtoBuf to serialize the target data to be sent to generate the first binary data. That is to say, when the target communication protocol is gRPC, the serialization method is fixed, i.e., ProtoBuf. When the target communication protocol is HTTP / 2 or HTTP / 1.1, the serialization method is not fixed, and can be other serialization methods other than ProtoBuf, and the serialization method when the target communication protocol is HTTP / 2 and the serialization method when the target communication protocol is HTTP / 1.1 can be the same, or different. That is, for HTTP / 2 or HTTP / 1.1, the serialization method and the communication protocol are independent of each other. However, for gRPC, the serialization method and the communication protocol are associated.

[0056] S102. Send a request message to the server using the target communication protocol, wherein the request message includes a first protocol header and the first message body, wherein the first protocol header includes a first field for identifying a serialization method and a second field for identifying a protocol version, and the first field and the second field are used to identify the target communication protocol.

[0057] For example, the client 21 adds a first protocol header in front of the first message body to form a request message, that is, the request message includes the first protocol header and the first message body. Among them, the first protocol header includes a first field and a second field, and the first field is recorded as the content type (Content-Type) field, and the Content-Type field is used to identify the serialization method of the target data by the client 21. For example, if the serialization method of the target data by the client 21 is ProtoBuf, the content of the Content-Type field is application / grpc+proto. The Chinese word for application is application, and proto is the abbreviation of protocol (Protocol). If the serialization method of the target data by the client 21 is JSON, the content of the Content-Type field is application / json. In addition, if the target communication protocol is HTTP / 1.1 or HTTP / 2, and the target data itself is binary data, the target data does not need to be serialized. At this time, the content of the Content-Type field is application / octet-stream, and octet-stream is a stream of octets of eight binary numbers. The second field is recorded as the Protocol-Version field, which is used to identify the protocol version for future expansion and compatibility processing. The Protocol-Version field is an optional field. Among them, the first field and the second field are used to identify the target communication protocol. Further, the client 21 uses the target communication protocol to send the request information to the server 23.

[0058] When the server 23 receives the request information, it first parses the first protocol header to obtain the first field and the second field, and identifies the target communication protocol used by the client 21 when sending the request information based on the first field and the second field. For example, if the content of the first field, i.e., the Content-Type field, is application / grpc+proto, and the content of the second field, i.e., the Protocol-Version field, is 2, the server 23 determines that the target communication protocol used by the client 21 when sending the request information is gRPC. If the content of the first field, i.e., the Content-Type field, is not application / grpc+proto, and the content of the second field, i.e., the Protocol-Version field, is 2, the server 23 determines that the target communication protocol used by the client 21 when sending the request information is HTTP / 2. If the content of the second field, i.e., the Protocol-Version field, is 1, regardless of the content of the first field, i.e., the Content-Type field, the server 23 determines that the target communication protocol used by the client 21 when sending the request information is HTTP / 1.1. Further, the server 23 can decapsulate the first message body to obtain the first binary data. In addition, the server 23 can also determine the parser used to parse the first binary data according to the first field, i.e., the Content-Type field. For example, if the content of the first field, i.e., the Content-Type field, is application / grpc+proto, the server 23 uses the gRPC parser to parse the first binary data to obtain the target data. If the content of the first field, i.e., the Content-Type field, is application / json, the server 23 uses the json parser to parse the first binary data to obtain the target data. Further, the server 23 can also generate response data according to the target data, and serialize the response data using the serialization method identified by the first field, i.e., the Content-Type field, to obtain the second binary data, and encapsulate the second binary data using the same encapsulation method as the client 21 to obtain the second message body. Further, the server 23 adds a second protocol header in front of the second message body to form feedback information, i.e., the feedback information includes the second protocol header and the second message body. The second protocol header similarly includes a first field and a second field. The content of the first field is the same as the content of the first field in the first protocol header as described above, and the content of the second field is the same as the content of the second field in the first protocol header as described above. That is to say, the server 23 can use the same target communication protocol as the client 21 to send feedback information to the client 21.

[0059] S103: Receive feedback information sent by the server using the target communication protocol, where the feedback information includes a second protocol header and a second message body, the second protocol header includes the first field and the second field, and the second message body includes second binary data.

[0060] For example, the client 21 receives feedback information sent by the server 23 using the target communication protocol, and the feedback information includes a second protocol header and a second message body. The second protocol header includes a first field and a second field. The second message body includes second binary data.

[0061] S104. According to the first field, use a parser corresponding to the serialization method to parse the second binary data to obtain response data.

[0062] For example, the client 21 determines the parser corresponding to the serialization mode according to the serialization mode identified by the first field, and the determination process is similar to the process of determining the parser by the server 23, which will not be repeated here. Further, the client 21 uses the parser to parse the second binary data to obtain response data.

[0063] In the disclosed embodiment, the client serializes the target data to be sent to the server to obtain the first binary data, and encapsulates the first binary data to obtain the first message body. Further, the client uses the target communication protocol to send a request message to the server, and the request message includes a first protocol header and a first message body. The first protocol header includes a first field for identifying the serialization method and a second field for identifying the protocol version. Among them, the first field and the second field can identify the target communication protocol used by the client, so that after receiving the request information, the server identifies the target communication protocol according to the first field and the second field, and uses the target communication protocol to send feedback information to the client, thereby realizing communication between the client and the server. In other words, without affecting compatibility, the client can dynamically select the communication protocol, and the server can dynamically identify the communication protocol. It avoids that some clients can only communicate with fixed servers, and some servers can only communicate with fixed clients, thereby improving the flexibility of communication between the client and the server.

[0064] Optionally, before serializing the target data to be sent to the server to obtain the first binary data, the method further includes: obtaining a target communication protocol with the highest priority among one or more communication protocols registered by the server in a registration center.

[0065] like Figure 2As shown, the client 21 sends a query request to the registration center 22, and the query request includes the service name corresponding to the server 23. The registration center 22 feeds back the registration information of the server 23 to the client 21 based on the service name. The client 21 extracts multiple communication protocols supported by the server 23 from the registration information, and further determines the target communication protocol with the highest priority from the multiple communication protocols. For example, the server 23 supports communication protocols such as HTTP / 1.1, HTTP / 2, and gRPC. The server 23 can register all the communication protocols supported by the server 23 in the registration center 22, or it can register some of the communication protocols supported by the server 23 in the registration center 22. In this embodiment, the priorities of gRPC, HTTP / 2, and HTTP / 1.1 decrease in sequence. If the server 23 registers HTTP / 1.1, HTTP / 2, and gRPC in the registration center 22, the client 21 determines that gRPC is the target communication protocol with the highest priority from these three communication protocols. If the server 23 registers HTTP / 1.1 and HTTP / 2 in the registration center 22, the client 21 determines that HTTP / 2 is the target communication protocol with the highest priority from these two communication protocols. In the embodiment of the present disclosure, the clients that can query the registration center by default are all clients that support the three communication protocols of HTTP / 1.1, HTTP / 2, and gRPC. Therefore, when the client 21 determines the target communication protocol with the highest priority from one or more communication protocols registered by the server 23 in the registration center 22, the client 21 also supports the target communication protocol. Therefore, the client 21 can use the target communication protocol to initiate a request to the server 23.

[0066] Optionally, the method further includes: dynamically adjusting the target communication protocol according to network conditions and / or the communication capabilities of the client, wherein the network conditions include network bandwidth and network delay, and the communication capabilities of the client include the number of request messages sent by the client in parallel.

[0067] In addition, in the disclosed embodiment, after the client selects the target communication protocol to communicate with the server according to the registration information of the server, the client can also dynamically adjust the target communication protocol according to the network condition and / or the communication capability of the client. Among them, the network condition includes factors such as network bandwidth and network delay. The communication capability of the client includes the number of request information sent by the client in parallel. For example, taking the network condition as an example, assuming that the target communication protocol selected by the client according to the registration information of the server is gRPC, during the communication process, if the network delay is higher than the first threshold and the network bandwidth is lower than the second threshold, the client can be downgraded to using HTTP / 1.1 to communicate with the server. If the network delay is lower than the first threshold and the network bandwidth is higher than the second threshold, the client can choose gRPC or HTTP / 2 to communicate with the server. In addition, the scope of the client's dynamic selection is the communication protocol registered by the server in the registration center, that is, if the server registers multiple communication protocols in the registration center, the client dynamically adjusts the target communication protocol, and the adjusted target communication protocol is one of the multiple communication protocols. For another example, taking the communication capability of the client as an example, if the number of request messages that the client can send in parallel is greater than the first preset value, the client gives priority to gRPC to communicate with the server. If the number of request messages that the client can send in parallel is less than the first preset value, the client can choose HTTP / 2 or HTTP / 1.1 to communicate with the server. For another example, taking the network status and the communication capability of the client as an example, the network bandwidth, network delay, and the request information that the client can send in parallel have corresponding weights, and the client dynamically adjusts the target communication protocol based on the weighted protocol selection algorithm. In addition, in other embodiments, it is not limited to dynamically adjusting the target communication protocol according to the network status and / or the communication capability of the client. For example, the target communication protocol is dynamically adjusted according to multiple factors such as the network status, the communication capability of the client, and the request type.

[0068] Optionally, the first message body includes a third field and the first binary data, the third field is located before the first binary data, and the third field is used to identify the length of the first binary data.

[0069] For example, the client 21 specifically uses the Length-Prefixed Message (LPM) format to encapsulate the first binary data, that is, a third field is added in front of the first binary data, and the third field is used to identify the length of the first binary data. The third field and the first binary data constitute a first message body, that is, the first message body is a message in the LPM format, and the first message body includes the third field and the first binary data, and the third field is located before the first binary data, and the third field is used to identify the length of the first binary data. Specifically, the third field can be a 4-byte field.

[0070] Optionally, using the target communication protocol to send request information to the server includes: sending a header frame and a data frame to the server in sequence, the header frame including the first protocol header, and the data frame including the first message body.

[0071] For example, after generating request information, namely, the first protocol header and the first message body, the client sends a header frame and a data frame to the server in sequence, wherein the header frame includes the first protocol header and the data frame includes the first message body.

[0072] Figure 3 A flow chart of a communication method provided by another embodiment of the present disclosure. The method is applied to the server. The specific steps of the method are as follows:

[0073] S301. Receive request information sent by a client, where the request information includes a first protocol header and a first message body, where the first protocol header includes a first field for identifying a serialization method and a second field for identifying a protocol version, and the first message body includes first binary data, where the first binary data is a result obtained by the client serializing target data using the serialization method.

[0074] For example Figure 2 As shown, the server 23 receives the request information sent by the client 21, and the request information includes a first protocol header and a first message body. The first protocol header includes a first field and a second field. The first field is recorded as the content type (Content-Type) field, and the Content-Type field is used to identify the serialization method of the target data by the client 21. The second field is recorded as the protocol version (Protocol-Version) field, which is used to identify the protocol version for future expansion and compatibility processing. The first message body includes first binary data, and the first binary data is the result obtained after the client 21 serializes the target data using the serialization method.

[0075] S302: Identify, according to the first field and the second field, the target communication protocol used by the client when sending the request information.

[0076] When the server 23 receives the request information, it first parses the first protocol header to obtain the first field and the second field, and identifies the target communication protocol used by the client 21 when sending the request information based on the first field and the second field. The specific identification process can refer to the identification process described in the above embodiment, which will not be repeated here.

[0077] S303: According to the first field, use a parser corresponding to the serialization method to parse the first binary data to obtain the target data.

[0078] For example, the server 23 can determine the parser used to parse the first binary data based on the first field, namely the Content-Type field. Specifically, if the content of the first field, namely the Content-Type field, is application / grpc+proto, the server 23 uses the gRPC parser to parse, namely deserialize, the first binary data to obtain the target data. If the content of the first field, namely the Content-Type field, is application / json, the server 23 uses the json parser to parse the first binary data to obtain the target data. In other words, the server 23 can identify the serialization method of the client 21 based on the Content-Type field, and use the parser corresponding to the serialization method to parse the first binary data, so that the server 23 can dynamically select the parsing method according to the Content-Type field.

[0079] S304: Generate response data according to the target data.

[0080] For example, the server 23 generates response data according to the target data.

[0081] S305: Serialize the response data in the serialization manner to obtain second binary data, and encapsulate the second binary data to obtain a second message body.

[0082] For example, the server 23 uses the serialization method identified by the first field, i.e., the Content-Type field, to serialize the response data to obtain the second binary data, and then uses the same encapsulation method as the client 21 to encapsulate the second binary data to obtain the second message body. For example, the server 23 uses the LPM format to encapsulate the second binary data, i.e., adds a third field in front of the second binary data, and the third field is used to identify the length of the second binary data. The third field and the second binary data constitute the second message body, i.e., the second message body is a message in the LPM format.

[0083] S306. Send feedback information to the client using the target communication protocol, where the feedback information includes a second protocol header and the second message body, and the second protocol header includes the first field and the second field.

[0084] Further, the server 23 adds a second protocol header in front of the second message body to form feedback information, that is, the feedback information includes the second protocol header and the second message body. The second protocol header similarly includes a first field and a second field, the content of the first field is the same as the content of the first field in the first protocol header as described above, and the content of the second field is the same as the content of the second field in the first protocol header as described above, that is, the server 23 can use the same target communication protocol as the client 21 to send feedback information to the client 21. It can be understood that the feedback information sent by the server 23 to the client 21 includes multiple data packets, the first data packet of the multiple data packets may include the second protocol header and the second message body, and each subsequent data packet may include the second message body without including the second protocol header.

[0085] In the disclosed embodiment, the client serializes the target data to be sent to the server to obtain the first binary data, and encapsulates the first binary data to obtain the first message body. Further, the client uses the target communication protocol to send a request message to the server, and the request message includes a first protocol header and a first message body. The first protocol header includes a first field for identifying the serialization method and a second field for identifying the protocol version. Among them, the first field and the second field can identify the target communication protocol used by the client, so that after receiving the request information, the server identifies the target communication protocol according to the first field and the second field, and uses the target communication protocol to send feedback information to the client, thereby realizing communication between the client and the server. In other words, without affecting compatibility, the client can dynamically select the communication protocol, and the server can dynamically identify the communication protocol. It avoids that some clients can only communicate with fixed servers, and some servers can only communicate with fixed clients, thereby improving the flexibility of communication between the client and the server.

[0086] Optionally, the target communication protocol is the communication protocol with the highest priority among one or more communication protocols registered by the server in the registration center; the target communication protocol is any one of the first communication protocol, the second communication protocol, and the third communication protocol; the priorities of the first communication protocol, the second communication protocol, and the third communication protocol decrease in sequence.

[0087] For example, the target communication protocol selected by the client 21 is the communication protocol with the highest priority among one or more communication protocols registered by the server 23 in the registration center. The target communication protocol obtained by the client 21 from the registration center can be one of gRPC, HTTP / 2, and HTTP / 1.1, and the priority of gRPC, HTTP / 2, and HTTP / 1.1 decreases in sequence. Here, gRPC is recorded as the first communication protocol, HTTP / 2 is recorded as the second communication protocol, and HTTP / 1.1 is recorded as the third communication protocol.

[0088] Optionally, based on the first field and the second field, identifying the target communication protocol used by the client when sending the request information, including: if the serialization method identified by the first field is a serialization method associated with the first communication protocol, and the protocol version identified by the second field is a first preset version, then determining that the target communication protocol used by the client when sending the request information is the first communication protocol.

[0089] For example, if the content of the first field, namely the Content-Type field, is application / grpc+proto, and the content of the second field, namely the Protocol-Version field, is the first preset version, such as 2, the server 23 determines that the target communication protocol used by the client 21 when sending the request information is gRPC.

[0090] Optionally, based on the first field and the second field, the target communication protocol adopted by the client when sending the request information is identified, including: if the serialization method identified by the first field is not a serialization method associated with the first communication protocol, and the protocol version identified by the second field is a first preset version, then it is determined that the target communication protocol adopted by the client when sending the request information is the second communication protocol.

[0091] If the content of the first field, namely the Content-Type field, is not application / grpc+proto, and the content of the second field, namely the Protocol-Version field, is 2, the server 23 determines that the target communication protocol used by the client 21 when sending the request information is HTTP / 2.

[0092] Optionally, based on the first field and the second field, identify the target communication protocol used by the client when sending the request information, including: if the protocol version identified by the second field is the second preset version, determine that the target communication protocol used by the client when sending the request information is the third communication protocol.

[0093] If the content of the second field, ie, the Protocol-Version field, is the second preset version, such as 1, then regardless of the content of the first field, ie, the Content-Type field, the server 23 determines that the target communication protocol used by the client 21 when sending the request information is HTTP / 1.1.

[0094] In addition, in HTTP / 2, the server can actively push data to the client without the client initiating a request to the server, thereby reducing the number of client requests and reducing request waiting.

[0095] The disclosed embodiments propose a new communication protocol based on HTTP / 2, which can use the Length-PrefixedMessage format for data transmission, and identify and support other data formats and serialization methods through the Content-Type field in the protocol header to ensure compatibility with HTTP / 1.1 and gRPC. This protocol is designed to simplify the communication between different protocols in modern Web services and microservices architectures, and provide an efficient and flexible data transmission method.

[0096] In the embodiment of the present disclosure, the request information sent by the client to the server and the feedback information sent by the server to the client are respectively as follows: Figure 4 The frame structure is shown in Figure 1. Figure 4 The length of the serialized result shown is indefinite, the length of the length field is a 4-byte integer, the length of the Content-Type field is indefinite, and the length of the Protocol-Version field is 4 bytes.

[0097] Figure 5 FIG. 1 is a schematic diagram of a communication method provided by another embodiment of the present disclosure. Figure 5As shown, after the client dynamically selects the target communication protocol according to the registration information of the server, the target data is serialized to obtain the first binary data. The target data can be business data, which is recorded as Object, and the first binary data can be a binary byte array, which is recorded as byte[]. Further, the client encapsulates the first binary data in LPM format to obtain a first message body, which is a message in LPM format, which is recorded as LPM message. Then, a protocol header is added in front of the first message body, which is recorded as HEADER. The protocol header is the first protocol header as described above, and the protocol header includes a Content-Type field and a Protocol-Version field. The client puts the first message body into a data frame (DATA Frame), puts the first protocol header into a header frame (HEADERFrame), and then sends the header frame to the server first, and then sends the data frame to the server. When the server receives the header frame, it extracts the protocol header, i.e., the first protocol header, from the header frame and parses the protocol header. Further, the server identifies the Content-Type field and the Protocol-Version field from the protocol header, identifies the target communication protocol used by the client according to the Content-Type field and the Protocol-Version field, and selects a corresponding parser according to the Content-Type field. Further, the server extracts the first message body from the data frame, and decapsulates the first message body to obtain the first binary data. Then, the corresponding parser is used to decode the first binary data, i.e., deserialize, to obtain the target data.

[0098] Figure 6 FIG. 1 is a schematic diagram of a communication method provided by another embodiment of the present disclosure. Figure 6As shown, the server can generate response data according to the target data as described above, and the response data can also be a kind of business data. Further, the response data is serialized in a serialization manner identified by the first field, i.e., the Content-Type field, to obtain second binary data, which can be a binary byte array, and the binary byte array is recorded as byte[]. Further, the server encapsulates the second binary data in LPM format to obtain a second message body, and the second message body is specifically a message in LPM format, and the message in LPM format is recorded as LPM message. Then, a protocol header is added in front of the second message body, and the protocol header is recorded as HEADER. The protocol header is the second protocol header as described above, and the protocol header includes the Content-Type field and the Protocol-Version field. The server puts the second message body into a data frame (DATA Frame), puts the second protocol header into a header frame (HEADER Frame), and then sends the header frame to the client first, and then sends the data frame to the client. When the client receives the header frame, the protocol header, i.e., the second protocol header, is extracted from the header frame, and the protocol header is parsed. Further, the client identifies the Content-Type field and the Protocol-Version field from the protocol header, identifies the target communication protocol adopted by the server according to the Content-Type field and the Protocol-Version field, and selects the corresponding parser according to the Content-Type field. Further, the client extracts the second message body from the data frame, and decapsulates the second message body to obtain the second binary data. Then, the corresponding parser is used to decode or deserialize the second binary data to obtain the response data. When the response data sent by the server ends, the server can send a special data frame to the client, which does not contain the second message body. When the client receives the special data frame, it can be determined that the response data sent by the server has ended.

[0099] In addition, the communication method described in the embodiment of the present disclosure supports multiple bidirectional streams between the client and the server through multiplexing. Figure 7As shown, after the client and the server establish a connection, the client can send multiple request messages to the server in parallel, and the server can send multiple feedback messages to the client in parallel. Among them, the client sends request information to the server, and the server sends feedback information to the client according to the request information to form a two-way data stream. Each request information includes a header frame and a data frame. Each feedback information includes a header frame and a data frame. In addition, a connection pool and a load balancer can be implemented on the client to ensure the maximum utilization of multiplexing. In addition, the priority (PRIORITY) frame of HTTP / 2 can also be used to optimize the scheduling of data streams to ensure that high-priority streams are transmitted first. In some other embodiments, the data stream can also be encrypted, for example, using the Transport Layer Security Protocol (Transport Layer Security, TLS) for encryption to ensure that the data stream is securely transmitted in the network, and to ensure that all data transmission is carried out in a secure encrypted channel, especially in a public network, to avoid data leakage or tampering. In addition, the communication protocols registered by the server in the registration center are not limited to gRPC, HTTP / 2, and HTTP / 1.1 as described above, but can also be extended to protocols such as WebSocket and Advanced Message Queuing Protocol (AMQP), thereby increasing the scalability of the system. At the same time, by providing standardized interfaces, developers can build distributed systems, microservice architectures, and hybrid cloud environments based on the protocol. Among them, WebSocket is a protocol for full-duplex communication on a single Transmission Control Protocol (TCP) connection. The communication method described in the embodiments of the present disclosure fully considers the protocol standards of HTTP / 1.1, HTTP / 2, and gRPC to ensure backward compatibility. The transmission efficiency and response speed of the system can be improved through technologies such as header compression and streaming data transmission.

[0100] In the embodiment of the present disclosure, if the client and the server use HTTP / 1.1 for communication, the first binary data or the second binary data can still be encapsulated as a message in LPM format, but a standard HTTP message structure is required to realize data flow through block transfer encoding. In addition, the protocol header may also include a keep-alive field, and the client and the server are ensured to have a persistent connection through connection management.

[0101] Figure 8 The communication device provided in the embodiment of the present disclosure is a schematic diagram of the structure of the communication device. The communication device is configured on the client. The communication device provided in the embodiment of the present disclosure can execute the processing flow provided in the communication method embodiment, such as Figure 8 As shown, the communication device 90 includes:

[0102] A serialization module 91, used for serializing the target data to be sent to the server to obtain first binary data;

[0103] An encapsulation module 92, configured to encapsulate the first binary data to obtain a first message body;

[0104] A sending module 93, configured to send a request message to the server using the target communication protocol, wherein the request message includes a first protocol header and the first message body, wherein the first protocol header includes a first field for identifying a serialization mode and a second field for identifying a protocol version, and the first field and the second field are used to identify the target communication protocol;

[0105] A receiving module 94 is used to receive feedback information sent by the server using the target communication protocol, wherein the feedback information includes a second protocol header and a second message body, the second protocol header includes the first field and the second field, and the second message body includes second binary data;

[0106] The parsing module 95 is used to parse the second binary data according to the first field by using a parser corresponding to the serialization method to obtain response data.

[0107] Optionally, the communication device 90 further includes an acquisition module 96 for acquiring a target communication protocol with the highest priority among one or more communication protocols registered by the server in the registration center before the serialization module 91 serializes the target data to be sent to the server to obtain the first binary data.

[0108] Optionally, the first message body includes a third field and the first binary data, the third field is located before the first binary data, and the third field is used to identify the length of the first binary data.

[0109] Optionally, when the sending module 93 uses the target communication protocol to send request information to the server, it is specifically used to: send a header frame and a data frame to the server in sequence, the header frame includes the first protocol header, and the data frame includes the first message body.

[0110] Optionally, the communication device 90 also includes a dynamic adjustment module 97, which is used to dynamically adjust the target communication protocol according to network conditions and / or the communication capabilities of the client, wherein the network conditions include network bandwidth and network delay, and the communication capabilities of the client include the number of request information sent by the client in parallel.

[0111] Figure 8The communication device of the illustrated embodiment can be used to execute the technical solution of the above-mentioned method embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.

[0112] Fig. 9 The communication device provided in the embodiment of the present disclosure is a schematic diagram of the structure of the communication device. The communication device is configured at the server end. The communication device provided in the embodiment of the present disclosure can execute the processing flow provided in the communication method embodiment, such as Fig. 9 As shown, the communication device 100 includes:

[0113] The receiving module 1001 is used to receive request information sent by a client, wherein the request information includes a first protocol header and a first message body, wherein the first protocol header includes a first field for identifying a serialization method and a second field for identifying a protocol version, and the first message body includes first binary data, wherein the first binary data is a result obtained after the client serializes the target data using the serialization method;

[0114] An identification module 1002, configured to identify, according to the first field and the second field, a target communication protocol used by the client when sending the request information;

[0115] A parsing module 1003, configured to parse the first binary data according to the first field by using a parser corresponding to the serialization method to obtain the target data;

[0116] A generating module 1004, configured to generate response data according to the target data;

[0117] A serialization processing module 1005, configured to serialize the response data in the serialization manner to obtain second binary data, and encapsulate the second binary data to obtain a second message body;

[0118] The sending module 1006 is used to send feedback information to the client using the target communication protocol, where the feedback information includes a second protocol header and the second message body, and the second protocol header includes the first field and the second field.

[0119] Optionally, the target communication protocol is the communication protocol with the highest priority among one or more communication protocols registered by the server in the registration center; the target communication protocol is any one of the first communication protocol, the second communication protocol, and the third communication protocol; the priorities of the first communication protocol, the second communication protocol, and the third communication protocol decrease in sequence.

[0120] Optionally, the identification module 1002 identifies the target communication protocol adopted by the client when sending the request information based on the first field and the second field, and is specifically used to: if the serialization method identified by the first field is a serialization method associated with the first communication protocol, and the protocol version identified by the second field is a first preset version, then determine that the target communication protocol adopted by the client when sending the request information is the first communication protocol.

[0121] Optionally, the identification module 1002 identifies the target communication protocol adopted by the client when sending the request information based on the first field and the second field, and is specifically used to: if the serialization method identified by the first field is not a serialization method associated with the first communication protocol, and the protocol version identified by the second field is a first preset version, then determine that the target communication protocol adopted by the client when sending the request information is the second communication protocol.

[0122] Optionally, the identification module 1002 identifies the target communication protocol adopted by the client when sending the request information based on the first field and the second field, and is specifically used to: if the protocol version identified by the second field is the second preset version, determine that the target communication protocol adopted by the client when sending the request information is the third communication protocol.

[0123] Fig. 9 The communication device of the illustrated embodiment can be used to execute the technical solution of the above-mentioned method embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.

[0124] The internal functions and structure of the communication device are described above. The device can be implemented as an electronic device. Fig.10 This is a schematic diagram of the structure of an electronic device embodiment provided by the present disclosure. Fig.10 As shown, the electronic device includes a memory 111 and a processor 112 .

[0125] The memory 111 is used to store programs. In addition to the above-mentioned programs, the memory 111 can also be configured to store various other data to support operations on the electronic device. Examples of such data include instructions for any application or method operating on the electronic device, contact data, phone book data, messages, pictures, videos, etc.

[0126] The memory 111 may be implemented by any type of volatile or nonvolatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0127] The processor 112 is coupled to the memory 111 and executes the program stored in the memory 111 to implement the technical solution of the above method embodiment.

[0128] Further, if Fig.10 As shown, the electronic device may also include: a communication component 113, a power component 114, an audio component 115, a display 116 and other components. Fig.10 Only some components are shown schematically, which does not mean that the electronic device only includes Fig.10 Components shown.

[0129] The communication component 113 is configured to facilitate wired or wireless communication between the electronic device and other devices. The electronic device can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 113 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 113 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

[0130] The power supply component 114 provides power to various components of the electronic device. The power supply component 114 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device.

[0131] The audio component 115 is configured to output and / or input audio signals. For example, the audio component 115 includes a microphone (MIC), and when the electronic device is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 111 or sent via the communication component 113. In some embodiments, the audio component 115 also includes a speaker for outputting audio signals.

[0132] The display 116 includes a screen, which may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.

[0133] In addition, an embodiment of the present disclosure further provides a computer-readable storage medium on which a computer program is stored. The computer program is executed by a processor to implement the method described in the above embodiment.

[0134] The exemplary embodiments of the present disclosure further provide a computer program product, including a computer program, wherein when the computer program is executed by a processor of a computer, it is used to enable the computer to implement the method described in the above embodiments.

[0135] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0136] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A communication method, wherein: The method is applied to a client, and the method comprises: Serializing the target data to be sent to the server to obtain first binary data, and encapsulating the first binary data to obtain a first message body; Using the target communication protocol to send a request message to the server, the request message includes a first protocol header and the first message body, the first protocol header includes a first field for identifying a serialization mode and a second field for identifying a protocol version, the first field and the second field are used to identify the target communication protocol; receiving feedback information sent by the server using the target communication protocol, the feedback information including a second protocol header and a second message body, the second protocol header including the first field and the second field, and the second message body including second binary data; According to the first field, the second binary data is parsed using a parser corresponding to the serialization method to obtain response data.

2. The method according to claim 1, wherein: Before serializing the target data to be sent to the server to obtain the first binary data, the method further includes: Obtain a target communication protocol with the highest priority among one or more communication protocols registered by the server in a registration center.

3. The method according to claim 1, wherein: The first message body includes a third field and the first binary data, the third field is located before the first binary data, and the third field is used to identify the length of the first binary data.

4. The method according to claim 1, wherein: Using the target communication protocol to send request information to the server includes: A header frame and a data frame are sent to the server in sequence, wherein the header frame includes the first protocol header, and the data frame includes the first message body.

5. The method according to claim 2, wherein: The method further comprises: The target communication protocol is dynamically adjusted according to the network condition and / or the communication capability of the client, wherein the network condition includes network bandwidth and network delay, and the communication capability of the client includes the number of request information sent by the client in parallel.

6. A communication method, wherein: The method is applied to the server, and the method includes: Receive request information sent by a client, the request information including a first protocol header and a first message body, the first protocol header including a first field for identifying a serialization method and a second field for identifying a protocol version, the first message body including first binary data, the first binary data being a result obtained after the client serializes the target data using the serialization method; Identify, according to the first field and the second field, a target communication protocol used by the client when sending the request information; According to the first field, using a parser corresponding to the serialization method to parse the first binary data to obtain the target data; generating response data according to the target data; The response data is serialized in the serialization manner to obtain second binary data, and the second binary data is encapsulated to obtain a second message body; Feedback information is sent to the client using the target communication protocol, where the feedback information includes a second protocol header and the second message body, and the second protocol header includes the first field and the second field.

7. The method according to claim 6, wherein: The target communication protocol is the communication protocol with the highest priority among one or more communication protocols registered by the server in the registration center; The target communication protocol is any one of the first communication protocol, the second communication protocol, and the third communication protocol; The priorities of the first communication protocol, the second communication protocol, and the third communication protocol decrease in sequence.

8. The method according to claim 7, wherein: Identifying, according to the first field and the second field, a target communication protocol used by the client when sending the request information, including: If the serialization method identified by the first field is a serialization method associated with the first communication protocol, and the protocol version identified by the second field is a first preset version, it is determined that the target communication protocol used by the client when sending the request information is the first communication protocol.

9. The method according to claim 7, wherein: Identifying, according to the first field and the second field, a target communication protocol used by the client when sending the request information, including: If the serialization method identified by the first field is not a serialization method associated with the first communication protocol, and the protocol version identified by the second field is a first preset version, it is determined that the target communication protocol used by the client when sending the request information is the second communication protocol.

10. The method according to claim 7, wherein: Identifying, according to the first field and the second field, a target communication protocol used by the client when sending the request information, including: If the protocol version identified by the second field is the second preset version, it is determined that the target communication protocol used by the client when sending the request information is the third communication protocol.

11. A communication device, wherein: The device is configured on a client, and includes: A serialization module, used for serializing the target data to be sent to the server to obtain first binary data; An encapsulation module, used for encapsulating the first binary data to obtain a first message body; A sending module, configured to send a request message to the server by using the target communication protocol, wherein the request message includes a first protocol header and the first message body, wherein the first protocol header includes a first field for identifying a serialization mode and a second field for identifying a protocol version, and the first field and the second field are used to identify the target communication protocol; A receiving module, configured to receive feedback information sent by the server using the target communication protocol, wherein the feedback information includes a second protocol header and a second message body, the second protocol header includes the first field and the second field, and the second message body includes second binary data; A parsing module is used to parse the second binary data according to the first field using a parser corresponding to the serialization method to obtain response data.

12. A communication device, wherein: The device is configured at the server end, and the device includes: A receiving module, configured to receive request information sent by a client, wherein the request information includes a first protocol header and a first message body, wherein the first protocol header includes a first field for identifying a serialization method and a second field for identifying a protocol version, and the first message body includes first binary data, wherein the first binary data is a result obtained after the client serializes the target data using the serialization method; an identification module, configured to identify, according to the first field and the second field, a target communication protocol used by the client when sending the request information; a parsing module, configured to parse the first binary data according to the first field by using a parser corresponding to the serialization method to obtain the target data; A generating module, used for generating response data according to the target data; A serialization processing module, used for serializing the response data in the serialization manner to obtain second binary data, and encapsulating the second binary data to obtain a second message body; A sending module is used to send feedback information to the client using the target communication protocol, wherein the feedback information includes a second protocol header and the second message body, and the second protocol header includes the first field and the second field.

13. An electronic device, wherein: include: Memory; processor; as well as Computer programs; The computer program is stored in the memory and is configured to be executed by the processor to implement the method according to any one of claims 1 to 10.

14. A computer-readable storage medium having a computer program stored thereon, wherein: When the computer program is executed by a processor, the method according to any one of claims 1 to 10 is implemented.

Citation Information

Cited By

  • GQL graph database server-side and client-side communication method based on gRPC protocol

    CN120091053A

  • A Communication Method between the Server and Client of a GQL Graph Database Based on the gRPC Protocol

    CN120091053B