Communication method, service node, distributed system, device and storage medium
UDP multicast technology realizes automatic connection between service nodes in distributed systems, solving the high cost of manually configuring connection information and improving connection efficiency and flexibility.
Patent Information
- Application Number
- CN202311435865.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-30
- Publication Date
- 2025-05-02
AI Technical Summary
In distributed systems with multi-service nodes, the prior art requires software developers to manually configure the connection information between service nodes, resulting in large configuration workloads, high time and labor costs.
Through UDP multicast technology, multiple service nodes join the same multicast address, automatically discover the connection information of other service nodes, and connect through UDP packets of different message types, without manual configuration.
Reduces the configuration workload of software developers, improves the connection efficiency between service nodes, supports dynamically changing network topology, and does not require a fixed startup sequence.
Smart Images

Figure CN119922190A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a communication method, a service node, a distributed system, an electronic device, and a computer-readable storage medium. Background Art
[0002] In a distributed system including multiple service nodes, in order for the multiple service nodes to work together, it is necessary to implement mutual networking between the multiple service nodes.
[0003] In the related art, software developers usually manually configure the connection information of other service nodes for each service node to achieve communication connection between the service node and other service nodes. When there are a large number of service nodes, the configuration workload of software developers is large, which requires high time and manpower costs. Summary of the invention
[0004] In view of this, the present application provides a communication method, a service node, a distributed system, an electronic device and a computer-readable storage medium.
[0005] Specifically, the present application is implemented through the following technical solutions:
[0006] According to a first aspect of an embodiment of the present application, a communication method is provided, which is applied to each service node of a plurality of service nodes included in a distributed system, wherein the plurality of service nodes are all added to the same multicast address; the method comprises:
[0007] In response to a first startup instruction of the service node, sending a first UDP data packet to the multicast address, the first UDP data packet including a first message type and connection information of the service node;
[0008] In response to receiving a first UDP data packet from the multicast address, recording connection information in the received first UDP data packet, and sending a second UDP data packet to the multicast address, wherein the second UDP data packet includes a second message type and connection information of the current service node;
[0009] In response to receiving a second UDP data packet from the multicast address, recording the connection information in the received second UDP data packet, and sending a third UDP data packet to the multicast address, the third UDP data packet including a third message type and connection information of the current service node.
[0010] In one implementation, in response to receiving a second UDP data packet from the multicast address, recording the connection information in the received second UDP data packet, and sending a third UDP data packet to the multicast address, comprises:
[0011] In response to the service node receiving a second UDP data packet from the multicast address for the first time after startup, recording the connection information in the received second UDP data packet, and sending a third UDP data packet to the multicast address;
[0012] In response to receiving a second UDP data packet from the multicast address not for the first time after the service node is started, query whether the connection information received in the second UDP data packet has been recorded in the service node; if not, record the connection information in the received second UDP data packet and send a third UDP data packet to the multicast address.
[0013] In one implementation, the method further includes:
[0014] In response to receiving a third UDP data packet from the multicast address, query whether the connection information in the received third UDP data packet has been recorded in the service node; if not, record the connection information in the received third UDP data packet.
[0015] In one implementation, the method further includes:
[0016] Based on the recorded connection information of other service nodes, a TCP connection is established with the other service nodes.
[0017] In one implementation, the connection information of any service node includes an IP address, a port number, and a unique identifier of the service node;
[0018] The unique identifier of the service node includes: a service identifier of the service node, and at least one of a device identifier of a device where the service node is located.
[0019] In one implementation, the method further includes:
[0020] In response to a second startup instruction after the abnormal shutdown of the service node, sending a fourth UDP data packet to the multicast address, wherein the fourth UDP data packet includes a fourth message type and a unique identifier of the service node;
[0021] In response to receiving a fourth UDP data packet from the multicast address, first target connection information is obtained from the recorded connection information through the unique identifier of the service node in the received fourth UDP data packet, and a TCP connection is established with the service node indicated by the received fourth UDP data packet based on the first target connection information.
[0022] In one implementation, the method further includes:
[0023] In response to the shutdown instruction of the service node, send a fifth UDP data packet to the multicast address and shut down the service node, the fifth UDP data packet including a fifth message type and a unique identifier of the service node;
[0024] In response to receiving the fifth UDP data packet from the multicast address, the second target connection information indicated by the unique identifier of the service node in the received fifth UDP data packet is deleted from the recorded connection information, and the TCP connection with the service node indicated by the received fifth UDP data packet is disconnected.
[0025] In one implementation, obtaining the IP address includes:
[0026] Check all network cards in the device where the service node is located in sequence until a target network card with a non-local loopback address, supporting an IPv4 address or an IPv6 address, being a non-virtual network card and being in working state is determined;
[0027] The IPV4 address or IPV6 address of the target network card is used as the IP address of the service node.
[0028] According to a second aspect of an embodiment of the present application, a service node is provided, which is applied to a distributed system, wherein multiple service nodes included in the distributed system are all added to the same multicast address; the service node includes a UDP multicast communication module, and the UDP multicast communication module includes:
[0029] A first communication unit, configured to send a first UDP data packet to the multicast address in response to a first startup instruction of the service node, wherein the first UDP data packet includes a first message type and connection information of the service node;
[0030] a second communication unit, configured to, in response to receiving a first UDP data packet from the multicast address, record the connection information in the received first UDP data packet, and send a second UDP data packet to the multicast address, wherein the second UDP data packet includes a second message type and the connection information of the current service node;
[0031] The third communication unit is used to record the connection information in the received second UDP data packet in response to receiving the second UDP data packet from the multicast address, and send a third UDP data packet to the multicast address, wherein the third UDP data packet includes a third message type and connection information of the service node.
[0032] According to a third aspect of an embodiment of the present application, there is provided an electronic device, including a memory, a processor, and executable instructions stored in the memory and executable on the processor;
[0033] Wherein, when the processor executes the executable instructions, the steps in the method as described in any one of the first aspects are implemented.
[0034] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which computer instructions are stored. When the computer instructions are executed by a processor, the steps of any one of the methods described in the first aspect are implemented.
[0035] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:
[0036] In the disclosed embodiment, multiple service nodes can be added to the same multicast address, and then through UDP multicast technology, multiple service nodes can automatically discover the connection information of other service nodes to achieve connection, without the need to manually configure the connection information, reducing the configuration workload of software developers, and helping to improve the connection efficiency between service nodes. In addition, by adding different message types to UDP data packets to form different UDP data packets, and based on the response mechanism of different UDP data packets, there is no need for a fixed startup order between the various service nodes, and the service node that is started later can also obtain the connection information of the service node that was started earlier, improving the convenience of use.
[0037] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. 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] Figure 1 It is a structural diagram of a distributed system shown in an exemplary embodiment of the present application.
[0040] Figure 2 It is a schematic diagram of the structure of another distributed system shown in an exemplary embodiment of the present application.
[0041] Figure 3 It is a flowchart of a communication method shown in an exemplary embodiment of the present application.
[0042] Figure 4 It is a structural diagram of a service node shown in an exemplary embodiment of the present application.
[0043] Figure 5A It is a schematic diagram of a first UDP data packet shown in an exemplary embodiment of the present application.
[0044] Figure 5BIt is a schematic diagram of a second UDP data packet shown in an exemplary embodiment of the present application.
[0045] Figure 5C It is a schematic diagram of a third UDP data packet shown in an exemplary embodiment of the present application.
[0046] Figure 6 It is an interaction sequence diagram between service node A and service node B shown in an exemplary embodiment of the present application.
[0047] Fig. 7A It is a schematic diagram of a fourth UDP data packet shown in an exemplary embodiment of the present application.
[0048] Figure 7B It is a schematic diagram of a fifth UDP data packet shown in an exemplary embodiment of the present application.
[0049] Figure 8 It is a schematic diagram of the structure of another service node shown in an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0050] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0051] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0052] It should be understood that although the terms first, second, third, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0053] See also Figure 1 , Figure 1A distributed system is shown, the distributed system includes multiple service nodes 100, each service node 100 is used to provide services to other service nodes 100, and the services include but are not limited to at least one of computing services, display services, and data collection services. Exemplarily, the service node 100 can be an application, hardware, or a combination of software and hardware with a certain function deployed in an electronic device, and this implementation does not impose any restrictions on this.
[0054] Among them, electronic devices include but are not limited to smart phones / mobile phones, tablet computers, personal digital assistants (PDAs), laptop computers, desktop computers, media content players, video game stations / systems, virtual reality systems, augmented reality systems, wearable devices (e.g., watches, glasses, gloves, headwear (e.g., hats, helmets, virtual reality headsets, augmented reality headsets, head-mounted devices (HMDs), headbands), pendants, armbands, leg rings, shoes, vests), three-dimensional scanners, or other devices.
[0055] Based on the mutual networking between multiple service nodes in the related art, the software developer needs to manually configure the connection information of other service nodes for each service node, which leads to a large configuration workload. The embodiment of the present application provides a communication method, multiple service nodes can be added to the same multicast address, and then through the UDP multicast technology, multiple service nodes can automatically discover the connection information of other service nodes to achieve connection, without the need to manually configure the connection information, reducing the configuration workload of software developers, and helping to improve the connection efficiency between service nodes. In addition, by adding different message types to UDP data packets to form different UDP data packets, and based on the response mechanism of different UDP data packets, there is no need for a fixed startup order between the various service nodes, and the service node that is started later can also obtain the connection information of the service node that was started earlier, which improves the convenience of use.
[0056] In an exemplary application scenario, see Figure 2 , taking the three-dimensional scanning scene as an example, the distributed system includes service node A, service node B, service node C and service node D. Service node A can be deployed on a three-dimensional scanner to provide image acquisition services. Service node B can be deployed on a device with computing functions (such as a computer, tablet, etc.) to provide point cloud processing services, such as point cloud reconstruction, etc. Service node C can be deployed on a device with computing functions (such as a computer, tablet, etc.) to provide point cloud processing services different from those of service node B, such as point cloud optimization, mesh post-processing, etc. Service node D can be deployed on a display device with display functions to provide point cloud display services.
[0057] Among them, (1) service node A and service node B have a communication connection requirement so that service node A can transmit the collected image to service node B for point cloud reconstruction. (2) service node A and service node D have a communication connection requirement so that service node A can transmit the collected image to service node D for display. (3) service node B and service node C have a communication connection requirement so that service node B can transmit the reconstructed point cloud to service node C for point cloud optimization. (4) service node C and service node D have a communication connection requirement so that service node C can send the optimized point cloud to service node D for display.
[0058] Based on the communication method provided in the embodiment of the present application, each service node can automatically discover the connection information of other service nodes based on UDP multicast technology, thereby realizing a communication connection between any two service nodes.
[0059] In some embodiments, see Figure 3 The embodiment of the present application provides a communication method, which is applied to each service node in a plurality of service nodes included in a distributed system, wherein the plurality of service nodes are all added to the same multicast address, and the method comprises:
[0060] In S101, in response to a first start instruction of the service node, a first UDP data packet is sent to the multicast address, where the first UDP data packet includes a first message type and connection information of the service node.
[0061] In S102, in response to receiving a first UDP data packet from the multicast address, the connection information in the received first UDP data packet is recorded, and a second UDP data packet is sent to the multicast address, wherein the second UDP data packet includes a second message type and connection information of the current service node.
[0062] In S103, in response to receiving a second UDP data packet from the multicast address, the connection information in the received second UDP data packet is recorded, and a third UDP data packet is sent to the multicast address, wherein the third UDP data packet includes a third message type and connection information of the service node.
[0063] Among them, step S101, step S102 and step S103 are different operations performed by the service node in response to different events, and are relatively independent to a certain extent. Figure 4It can be understood that each service node 100 in the distributed system includes a UDP multicast communication module 20, and the UDP multicast communication module 20 further includes: a first communication unit 21, a second communication unit 22 and a third communication unit 23. Each communication unit is independent of each other and responds to events to perform its own operations; for example, the first communication unit 21 responds to the first start instruction to send the first UDP data packet, and this process is not affected by other communication units; the second communication unit 22 and the third communication unit 23 are the same.
[0064] In this embodiment, multiple service nodes can be added to the same multicast address, and then through the UDP multicast technology, multiple service nodes can automatically discover the connection information of other service nodes to achieve connection, without the need to manually configure the connection information, reducing the configuration workload of software developers, and helping to improve the connection efficiency between service nodes; and by using the multicast address as the communication target, the UDP data packet transmission can be extended to multiple service nodes, without the need to establish an independent connection for each service node, which enables the distributed system to adapt to dynamically changing network topologies and support the dynamic joining and exit of service nodes, with strong flexibility. In addition, by adding different message types to the UDP data packet to form different UDP data packets, and based on the response mechanism of different UDP data packets, there is no need for a fixed startup order between the various service nodes, the previously started service node can obtain the connection information of the later started service node, and the later started service node can also obtain the connection information of the previously started service node, which improves the convenience of use.
[0065] Exemplarily, for S101, after any service node is started, the service node may first obtain its own connection information. The connection information of any service node includes an IP address, a port number, and a unique identifier of the service node. The unique identifier of the service node includes: a service identifier of the service node, and at least one of a device identifier of a device where the service node is located. Exemplarily, the service identifier and the device identifier may be composed of at least one of numbers, English characters, Chinese characters, operation symbols, punctuation marks, and other functional symbols, and this embodiment does not impose any restrictions on this.
[0066] For the IP address, if at least two network cards are set on the device where the service node is located, the service node can check all the network cards in the device where the service node is located in turn until a target network card that is a non-local loopback address, supports an IPV4 address or an IPV6 address, is not a virtual network card and is in a working state is determined, and then the IPV4 address or IPV6 address of the target network card is used as the IP address of the service node.
[0067] In addition, if there is only one network card on the device where the service node is located, you can check whether the network card meets the following conditions: it is a non-local loopback address, supports IPV4 address or IPV6 address, is not a virtual network card and is in working state; if it meets the conditions, the IPV4 address or IPV6 address of the network card is used as the IP address of this service node; if it does not meet the conditions, the subsequent step of sending the first UDP data packet will not be performed.
[0068] For the port number, in one possible implementation, you can use the QTcpServer class of the Qt library and obtain the port number of the service node through the serverPort method of the QTcpServer class. Of course, other methods can also be used. For example, some common applications and protocols use specific default port numbers, which can be found on the official website; for example, HTTP usually uses port 80, HTTPS usually uses port 443, and SSH usually uses port 22. For example, on Windows devices, you can use command-line tools (such as netstat) to display the currently open port number. For example, on Linux devices and Mac devices, you can use command-line tools (such as netstat or lsof) to query the port number.
[0069] For the unique identifier of the service node, if one service node is deployed in the same device, the unique identifier of the service node may be the service identifier of the service node, or the device identifier of the device where the service node is located, or a combination of the two. If at least two service nodes are deployed in the same device, the unique identifier of each service node may be the service identifier of the service node, or a combination of the service identifier of the service node and the device identifier of the device where the service node is located.
[0070] After any service node obtains the connection information of the service node, it can assemble it according to the preset UDP multicast communication protocol packet format to obtain the following: Figure 5A The first UDP data packet shown includes a first message type and connection information of the service node. The first message type represents a broadcast message, that is, the service node started later broadcasts its own connection information to the service node started earlier, and the connection information corresponding to the service node started later is not recorded in any other service node. Then the service node sends the first UDP data packet to the pre-joined multicast address, so that other service nodes joined to the multicast address can receive the first UDP data packet.
[0071] The first message type may be represented by at least one of a number and a character, such as Figure 5A As shown, the first message type is "0x01".
[0072] For S102, after any service node receives a UDP data packet from the multicast address, it parses the UDP data packet. If the first message type and connection information are obtained through the parsing, it can be determined that the first UDP data packet has been received. The service node can respond to receiving the first UDP data packet from the multicast address (or respond to the first message type in the first UDP data packet), record the connection information in the received first UDP data packet, and then assemble its own connection information according to the preset UDP multicast communication protocol packet format to obtain the following: Figure 5B The second UDP data packet shown in the figure includes the second message type and the connection information of the service node. The second message type represents the response information, that is, the service node started first can feed back its connection information to the service node started later. Then the service node sends the second UDP data packet to the pre-joined multicast address, so that other service nodes joined to the multicast address can receive the second UDP data packet.
[0073] The second message type may be represented by at least one of a number and a character, such as Figure 5B As shown, the second message type is "0x02".
[0074] For S103, after receiving a UDP data packet from the multicast address, any service node parses the UDP data packet. If the second message type and connection information are obtained through the parsing, it is determined that the second UDP data packet has been received. The service node can respond to receiving the second UDP data packet from the multicast address (or respond to the second message type in the second UDP data packet), record the connection information in the received second UDP data packet, and then assemble its own connection information according to the preset UDP multicast communication protocol packet format to obtain the following: Figure 5C The third UDP data packet shown includes a third message type and the connection information of this service node. Among them, the third message type represents the end information, that is, the service node that is started later has obtained the connection information of the service node that is started earlier. Then the service node sends the third UDP data packet to the multicast address, so that other service nodes that have joined the multicast address can receive the third UDP data packet. In this embodiment, any service node responds to receiving the second UDP data packet from the multicast address, and sends the third UDP data packet containing its own connection information to the multicast address again, which can improve reliability and fault tolerance. Even if some service nodes miss the first UDP data packet at a certain point in time, they still have the opportunity to obtain the connection information of the service node in subsequent data packets, thereby ensuring the stable operation of the entire distributed system.
[0075] The third message type may be represented by at least one of a number and a character, such as Figure 5C As shown, the third message type is represented by "0x03".
[0076] See also Figure 6 Here, we take service node A (started later) and service node B (started earlier) as examples to illustrate the interaction process between service nodes:
[0077] 11. After service node A is started, it generates a first UDP data packet including a first message type and connection information of service node A, and sends it to the multicast address;
[0078] 12. Service node B receives the first UDP data packet from the multicast address and records the connection information of service node A in the first UDP data packet;
[0079] 13. Service node B generates a second UDP data packet including a second message type and connection information of service node B, and sends it to the multicast address;
[0080] 14. Service node A receives the second UDP data packet from the multicast address and records the connection information of service node B in the second UDP data packet;
[0081] 15. Service node A generates a third UDP data packet including a third message type and connection information of service node A, and sends it to the multicast address.
[0082] In some embodiments, considering that when the service node sends the second UDP data packet to the multicast address, not only the service node started later will receive the second UDP data packet, but also the service node started earlier will receive the second UDP data packet. Therefore, in one case, any service node can directly record the connection information in the received second UDP data packet and send the third UDP data packet to the multicast address in response to the service node receiving the second UDP data packet from the multicast address for the first time after starting, that is, the service node does not record the connection information of any other service node after starting.
[0083] In another case, any service node may respond to receiving a second UDP data packet from the multicast address not for the first time after the service node is started, that is, the service node may be the service node that is started first. The service node may then query whether the connection information received in the second UDP data packet has been recorded in the service node; if not, record the connection information in the received second UDP data packet and send a third UDP data packet to the multicast address; if so, ignore the received second UDP data packet.
[0084] In some embodiments, after receiving a UDP data packet from a multicast address, any service node parses the UDP data packet. If the third message type and connection information are obtained through the parsing, it is determined that the third UDP data packet has been received. The service node can respond to receiving the third UDP data packet from the multicast address (or respond to the third message type in the third UDP data packet) and query whether the connection information in the received third UDP data packet has been recorded in the service node; if not, record the connection information in the received third UDP data packet; if so, ignore the received third UDP data packet. This allows some service nodes to miss the first UDP data packet at a certain point in time, and they still have the opportunity to obtain the connection information of the service node in subsequent data packets, thereby ensuring the stable operation of the entire distributed system.
[0085] In some embodiments, after the above process, any service node records the connection information of other service nodes in the service node, and then any service node can establish a TCP connection with the other service node based on actual needs and the recorded connection information of other service nodes. For example, when any service node determines that the target service node to be connected is not on the device where the service node is located, it establishes a TCP connection with the target service node based on the recorded connection information of the target service node. Figure 2 As shown, multiple service nodes are connected to each other in communication.
[0086] In some embodiments, when a service node in the distributed system needs to be shut down normally, such as receiving a shutdown instruction triggered by a user, any service node can respond to the shutdown instruction of the service node and generate the following Fig. 7AThe fifth UDP data packet includes the fifth message type and the unique identifier of the service node, and then the fifth UDP data packet is sent to the multicast address, and the service node is closed. Correspondingly, after any service node receives the UDP data packet from the multicast address, it parses the UDP data packet. If the fifth message type and the unique identifier of the service node are obtained by parsing, it is determined that the fifth UDP data packet has been received. The service node can respond to receiving the fifth UDP data packet from the multicast address (or respond to the fifth message type in the fifth UDP data packet), delete the second target connection information indicated by the unique identifier of the service node in the received fifth UDP data packet from the recorded connection information, and disconnect the TCP connection with the service node indicated by the received fifth UDP data packet. In this embodiment, when a service node is closed, other service nodes can disconnect the TCP connection with the service node and delete the relevant connection information, thereby effectively releasing resources and avoiding invalid connections. It also makes the recorded connection information consistent with the real network topology, avoids the use of expired or invalid information in subsequent operations, and ensures the data and state consistency of the distributed system.
[0087] The fifth message type may be represented by at least one of numbers and characters, such as Fig. 7A As shown, the fifth message type is represented by "0x05".
[0088] For example, see Figure 2 In the distributed system shown, when service node A receives the shutdown instruction, it sends the generated fifth UDP data packet to the multicast address and shuts down the service node; service node B, service node C, and service node D receive the fifth UDP data packet, delete the connection information of service node A from the recorded connection information according to the unique identifier of service node A carried in the fifth UDP data packet, and disconnect the TCP connection with service node A. When service node A is started again after being shut down normally, step S101 needs to be re-executed.
[0089] In some embodiments, considering the abnormal shutdown of the service node, such as power outage, node downtime, etc., the service node is directly offline without sending offline broadcast messages. When the service node is restarted after abnormal shutdown, since other service nodes still save the connection information of the restarted service node, the restarted service node can perform the abnormal offline reconnection process. Specifically, any service node can respond to the second startup instruction of the service node after abnormal shutdown, generate the following Figure 7BThe fourth UDP data packet includes a fourth message type and a unique identifier of the service node, and then sends the fourth UDP data packet to the multicast address. Correspondingly, after any service node receives a UDP data packet from the multicast address, it can parse the UDP data packet. If the fourth message type and the unique identifier of the service node are obtained by parsing, it is determined that the fourth UDP data packet has been received. The service node can respond to receiving the fourth UDP data packet from the multicast address (or respond to the fourth message type in the fourth UDP data packet), obtain the first target connection information from the recorded connection information through the unique identifier of the service node in the received fourth UDP data packet, and establish a TCP connection with the service node indicated by the received fourth UDP data packet based on the first target connection information. In this embodiment, by utilizing the undeleted connection information stored in other computing units, the reconnection function can be quickly realized without sending the UDP data packet carrying the connection information again, which is conducive to reducing the data volume of the UDP data packet and can greatly reduce the network bandwidth required to be occupied.
[0090] The fourth message type may be represented by at least one of a number and a character, such as Figure 7B As shown, the fourth message type is represented by "0x04".
[0091] For example, see Figure 2 In the distributed system shown, when service node A is restarted after an abnormal shutdown, the generated fourth UDP data packet is sent to the multicast address; service node B, service node C, and service node D receive the fourth UDP data packet, and according to the unique identifier of service node A carried in the fourth UDP data packet, find the connection information of service node A from the recorded connection information, and re-establish a TCP connection with service node A based on the connection information of service node A.
[0092] It is not difficult to understand that the solutions described in the above embodiments can be combined when there is no conflict, and they are not listed one by one in the embodiments of the present disclosure.
[0093] In some embodiments, see Figure 4 The embodiment of the present application further provides a service node 100, which is applied to a distributed system. The distributed system includes multiple service nodes 100 forming a distributed system, and the multiple service nodes 100 are all added to the same multicast address; the service node 100 includes a UDP multicast communication module 20, and the UDP multicast communication module 20 includes:
[0094] The first communication unit 21 is used to send a first UDP data packet to the multicast address in response to a first startup instruction of the service node, wherein the first UDP data packet includes a first message type and connection information of the service node;
[0095] The second communication unit 22 is used for recording the connection information in the received first UDP data packet in response to receiving the first UDP data packet from the multicast address, and sending a second UDP data packet to the multicast address, wherein the second UDP data packet includes the second message type and the connection information of the current service node;
[0096] The third communication unit 23 is used to record the connection information in the received second UDP data packet in response to receiving the second UDP data packet from the multicast address, and send a third UDP data packet to the multicast address, wherein the third UDP data packet includes a third message type and connection information of the service node.
[0097] In some embodiments, the third communication unit 23 is specifically used to: in response to the service node receiving the second UDP data packet from the multicast address for the first time after startup, record the connection information in the received second UDP data packet, and send the third UDP data packet to the multicast address; in response to the service node receiving the second UDP data packet from the multicast address not for the first time after startup, query whether the connection information received in the second UDP data packet has been recorded in the service node; if not, record the connection information in the received second UDP data packet, and send the third UDP data packet to the multicast address.
[0098] In some embodiments, see Figure 8 The UDP multicast communication module 20 also includes: a fourth communication unit 24, which is used to query whether the connection information received in the third UDP data packet has been recorded in the current service node in response to receiving the third UDP data packet from the multicast address; if not, record the connection information in the received third UDP data packet.
[0099] In some embodiments, see Figure 8 The service node 100 further includes a TCP connection module 30, which is used to establish a TCP connection with other service nodes based on the recorded connection information of the other service nodes.
[0100] In some embodiments, the connection information of any service node includes an IP address, a port number, and a unique identifier of the service node; wherein the unique identifier of the service node includes: a service identifier of the service node, and at least one of a device identifier of a device where the service node is located.
[0101] In some embodiments, see Figure 8, the UDP multicast communication module 20 also includes:
[0102] The fifth communication unit 25 is used to send a fourth UDP data packet to the multicast address in response to a second startup instruction after the abnormal shutdown of the service node, wherein the fourth UDP data packet includes a fourth message type and a unique identifier of the service node.
[0103] The sixth communication unit 26 is used to obtain the first target connection information from the recorded connection information through the unique identifier of the service node in the received fourth UDP data packet in response to receiving the fourth UDP data packet from the multicast address, and establish a TCP connection with the service node indicated by the received fourth UDP data packet based on the first target connection information.
[0104] In some embodiments, see Figure 8 , the UDP multicast communication module 20 also includes:
[0105] The seventh communication unit 27 is used to send a fifth UDP data packet to the multicast address and close the service node in response to the closing instruction of the service node, wherein the fifth UDP data packet includes a fifth message type and a unique identifier of the service node.
[0106] The eighth communication unit 28 is used to delete the second target connection information indicated by the unique identifier of the service node in the received fifth UDP data packet from the recorded connection information in response to receiving the fifth UDP data packet from the multicast address, and disconnect the TCP connection between the service node indicated by the received fifth UDP data packet.
[0107] In some embodiments, see Figure 8 The service node 100 also includes a connection information acquisition module 10, which is used to check all network cards in the device where the service node is located in sequence until a target network card that belongs to a non-local loopback address, supports an IPV4 address or an IPV6 address, is a non-virtual network card and is in a working state is determined; and the IPV4 address or IPV6 address of the target network card is used as the IP address of the service node.
[0108] The connection information acquisition module 10 is also used to obtain the port number and the unique identifier of the service node.
[0109] The implementation process of the functions and effects of each module in the above service node is specifically described in the implementation process of the corresponding steps in the above method, which will not be repeated here.
[0110] In some embodiments, see Figure 1 and Figure 2The embodiment of the present application also provides a distributed system, including multiple service nodes 100 as described above, and the multiple service nodes 100 are all added to the same multicast address.
[0111] Accordingly, an embodiment of the present application further provides an electronic device, including a memory, a processor, and executable instructions stored in the memory and executable on the processor;
[0112] Wherein, the processor implements the steps in the above method when executing the executable instructions.
[0113] Exemplarily, the processor includes but is not limited to a central processing unit (CPU), a graphics processing unit (GPU), a digital signal processor (DSP), an application specific integrated circuit (ASIC), or a field-programmable gate array (FPGA).
[0114] Exemplarily, the memory may include at least one type of storage medium, the storage medium including flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc.
[0115] Accordingly, an embodiment of the present application further provides a computer program product, including a computer program, which is used to implement the above method when executed by a processor.
[0116] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory including instructions, and the above instructions can be executed by a processor of the device to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0117] A non-transitory computer-readable storage medium, when the instructions in the storage medium are executed by a processor of a terminal, enables the terminal to execute the above method.
[0118] The embodiments of the subject matter and functional operations described in this specification may be implemented in the following: digital electronic circuits, tangibly embodied computer software or firmware, computer hardware including the structures disclosed in this specification and their structural equivalents, or a combination of one or more of them. The embodiments of the subject matter described in this specification may be implemented as one or more computer programs, i.e., one or more modules in computer program instructions encoded on a tangible non-temporary program carrier to be executed by a data processing device or to control the operation of the data processing device. Alternatively or additionally, the program instructions may be encoded on an artificially generated propagation signal, such as a machine-generated electrical, optical or electromagnetic signal, which is generated to encode information and transmit it to a suitable receiver device for execution by a data processing device. The computer storage medium may be a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or a combination of one or more of them.
[0119] The processes and logic flows described in this specification can be performed by one or more programmable computers executing one or more computer programs to perform corresponding functions by operating on input data and generating output. The processes and logic flows can also be performed by special purpose logic circuits, such as FPGAs (field programmable gate arrays) or ASICs (application-specific integrated circuits), and the apparatus can also be implemented as special purpose logic circuits.
[0120] Computers suitable for executing computer programs include, for example, general and / or special microprocessors, or any other type of central processing unit. Typically, the central processing unit will receive instructions and data from a read-only memory and / or a random access memory. The basic components of a computer include a central processing unit for implementing or executing instructions and one or more memory devices for storing instructions and data. Typically, the computer will also include one or more large-capacity storage devices for storing data, such as magnetic disks, magneto-optical disks, or optical disks, or the computer will be operably coupled to this large-capacity storage device to receive data from it or to transmit data to it, or both. However, the computer does not necessarily have such a device. In addition, the computer can be embedded in another device, such as a mobile phone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a global positioning system (GPS) receiver, or a portable storage device such as a universal serial bus (USB) flash drive, to name a few.
[0121] Computer readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media and memory devices, including, for example, semiconductor memory devices (e.g., EPROM, EEPROM and flash memory devices), magnetic disks (e.g., internal hard disks or removable disks), magneto-optical disks, and CD ROM and DVD-ROM disks. The processor and memory may be supplemented by, or incorporated in, special purpose logic circuitry.
[0122] Although this specification includes many specific implementation details, these should not be interpreted as limiting the scope of any invention or the scope of protection claimed, but are mainly used to describe the features of the specific embodiments of specific inventions. Certain features described in multiple embodiments in this specification may also be implemented in combination in a single embodiment. On the other hand, the various features described in a single embodiment may also be implemented separately in multiple embodiments or in any suitable sub-combination. In addition, although features may work in certain combinations as described above and even initially claim protection, one or more features from the claimed combination may be removed from the combination in some cases, and the claimed combination may point to a sub-combination or a variation of a sub-combination.
[0123] Similarly, although operations are depicted in a particular order in the accompanying drawings, this should not be understood as requiring that these operations be performed in the particular order shown or performed sequentially, or requiring that all illustrated operations be performed to achieve the desired results. In some cases, multitasking and parallel processing may be advantageous. In addition, the separation of various system modules and components in the above-described embodiments should not be understood as requiring such separation in all embodiments, and it should be understood that the described program components and systems can generally be integrated together in a single software product, or packaged into multiple software products.
[0124] Thus, specific embodiments of the subject matter have been described. Other embodiments are within the scope of the appended claims. In some cases, the actions recited in the claims can be performed in a different order and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the particular order or sequential order shown to achieve the desired results. In some implementations, multitasking and parallel processing may be advantageous.
[0125] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A communication method, characterized in that: Applied to each service node among a plurality of service nodes included in a distributed system, the plurality of service nodes are all added to the same multicast address; the method comprises: In response to a first startup instruction of the service node, sending a first UDP data packet to the multicast address, the first UDP data packet including a first message type and connection information of the service node; In response to receiving a first UDP data packet from the multicast address, recording connection information in the received first UDP data packet, and sending a second UDP data packet to the multicast address, wherein the second UDP data packet includes a second message type and connection information of the current service node; In response to receiving a second UDP data packet from the multicast address, recording the connection information in the received second UDP data packet, and sending a third UDP data packet to the multicast address, the third UDP data packet including a third message type and connection information of the current service node.
2. The method according to claim 1, characterized in that In response to receiving a second UDP data packet from the multicast address, recording the connection information in the received second UDP data packet, and sending a third UDP data packet to the multicast address, comprises: In response to the service node receiving a second UDP data packet from the multicast address for the first time after startup, recording the connection information in the received second UDP data packet, and sending a third UDP data packet to the multicast address; In response to receiving a second UDP data packet from the multicast address not for the first time after the service node is started, query whether the connection information received in the second UDP data packet has been recorded in the service node; if not, record the connection information in the received second UDP data packet and send a third UDP data packet to the multicast address.
3. The method according to claim 1, characterized in that Also includes: In response to receiving a third UDP data packet from the multicast address, querying whether the connection information received in the third UDP data packet has been recorded in the service node; If not, record the connection information in the received third UDP data packet.
4. The method according to claim 1, characterized in that: Also includes: Based on the recorded connection information of other service nodes, a TCP connection is established with the other service nodes.
5. The method according to any one of claims 1 to 4, characterized in that: The connection information of any service node includes the IP address, port number and the unique identifier of the service node; The unique identifier of the service node includes: a service identifier of the service node, and at least one of a device identifier of a device where the service node is located.
6. The method according to claim 5, characterized in that Also includes: In response to a second startup instruction after the abnormal shutdown of the service node, sending a fourth UDP data packet to the multicast address, wherein the fourth UDP data packet includes a fourth message type and a unique identifier of the service node; In response to receiving a fourth UDP data packet from the multicast address, first target connection information is obtained from the recorded connection information through the unique identifier of the service node in the received fourth UDP data packet, and a TCP connection is established with the service node indicated by the received fourth UDP data packet based on the first target connection information.
7. The method according to claim 5, characterized in that Also includes: In response to the shutdown instruction of the service node, send a fifth UDP data packet to the multicast address and shut down the service node, the fifth UDP data packet including a fifth message type and a unique identifier of the service node; In response to receiving the fifth UDP data packet from the multicast address, the second target connection information indicated by the unique identifier of the service node in the received fifth UDP data packet is deleted from the recorded connection information, and the TCP connection with the service node indicated by the received fifth UDP data packet is disconnected.
8. The method according to claim 5, characterized in that Obtaining an IP address includes: Check all network cards in the device where the service node is located in sequence until a target network card with a non-local loopback address, supporting an IPv4 address or an IPv6 address, being a non-virtual network card and being in working state is determined; The IPV4 address or IPV6 address of the target network card is used as the IP address of the service node.
9. A service node, characterized in that: Applied to a distributed system, the distributed system includes multiple service nodes that are all added to the same multicast address; the service node includes a UDP multicast communication module, and the UDP multicast communication module includes: A first communication unit, configured to send a first UDP data packet to the multicast address in response to a first startup instruction of the service node, wherein the first UDP data packet includes a first message type and connection information of the service node; a second communication unit, configured to, in response to receiving a first UDP data packet from the multicast address, record the connection information in the received first UDP data packet, and send a second UDP data packet to the multicast address, wherein the second UDP data packet includes a second message type and the connection information of the current service node; The third communication unit is used to record the connection information in the received second UDP data packet in response to receiving the second UDP data packet from the multicast address, and send a third UDP data packet to the multicast address, wherein the third UDP data packet includes a third message type and connection information of the service node.
10. A distributed system, characterized in that: The method comprises a plurality of service nodes as claimed in claim 9, wherein the plurality of service nodes are all added to the same multicast address.
11. An electronic device, characterized in that: including a memory, a processor, and executable instructions stored in the memory and executable on the processor; Wherein, when the processor executes the executable instructions, the steps in the method as described in any one of claims 1 to 8 are implemented.
12. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer instructions are executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.