Distributed Socket communication method and device and medium

By introducing distributed nodes and load balancers in traditional Socket communication, the problem of centralized servers limiting concurrent processing capabilities is solved, efficient data transmission and stable communication are achieved, and the needs of large-scale network applications are met.

CN120075168APending Publication Date: 2025-05-30NAVAL AVIATION UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510058023.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-14
Publication Date
2025-05-30

AI Technical Summary

Technical Problem

The traditional Socket communication mechanism using centralized servers limits the system's ability to process concurrent requests, resulting in low data transmission efficiency and unable to meet the rapid development of computer network applications.

Method used

By building distributed nodes and using the registration center to obtain node status information, the load balancer selects the server nodes to allocate Socket connection requests based on the status information and allocation policies, and synchronizes data and status among each node to achieve connection fault tolerance and expansion.

Benefits of technology

It enhances the system's concurrent processing capabilities and data transmission efficiency, provides good fault tolerance, ensures the stability of communication, and meets the scalability needs of large-scale network applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120075168A_ABST
    Figure CN120075168A_ABST
Patent Text Reader

Abstract

The invention provides a distributed Socket communication method and device and a medium, and belongs to the technical field of network communication, and the method comprises the following steps: constructing a plurality of distributed nodes supporting a Socket connection request based on a centralized server; the registration center obtains state information of each node; the load balancer receives a Socket connection request serving as a node of a client, and selects the node as a server according to the state information of each node and a preset allocation strategy to allocate the Socket connection request; and establishing a Socket connection request between the node of the server and the end node of the client, and determining a routing path. According to the invention, an extensible distributed communication architecture is applied to a large-scale network, the concurrent processing capability and the data transmission efficiency of the system are enhanced, good fault-tolerant capability is provided, and the stability of communication is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of network communication, and particularly relates to a distributed Socket communication method, device and medium. Background Art

[0002] Socket is a network programming interface independent of protocols, that is, a socket. An application program can send or receive data through Socket. Socket supports an application program to insert I / O into the network and communicate with other application programs in the network. A network socket is a combination of an IP address and a port. Socket enables different programs to exchange data on the network.

[0003] For large-scale network applications such as cloud computing services, big data processing platforms, and online game services, high-availability and high-concurrency network performance are required. In traditional Socket communication mechanisms, a centralized server is often adopted, and the centralized server limits the system's ability to handle a large number of concurrent connections and data streams, becoming a bottleneck in the entire network communication. With the rapid development of computer network applications, the demand for high-performance distributed communication mechanisms is increasing day by day. However, the existing centralized servers limit the system's ability to handle concurrent requests, resulting in low data transmission efficiency and poor stability.

[0004] In summary, the traditional Socket using a centralized server restricts the ability to concurrently process data, resulting in low data transmission efficiency and being unable to meet the requirements of the rapid development of computer network applications.

[0005] This is the shortcoming of the prior art. Therefore, it is very necessary to provide a distributed Socket communication method, device and medium to address the above-mentioned defects in the prior art. Summary of the Invention

[0006] In view of the above-mentioned defect that the traditional Socket using a centralized server in the prior art restricts the ability to concurrently process data, resulting in low data transmission efficiency and being unable to meet the requirements of the rapid development of computer network applications, the present invention provides a distributed Socket communication method, device and medium to solve the above technical problems.

[0007] In a first aspect, the present invention provides a distributed Socket communication method, including the following steps: S1. Based on a centralized server, construct a number of distributed nodes that support Socket connection requests; S2. The registration center obtains the status information of each node; S3. The load balancer receives the Socket connection request from the node acting as the client, and selects a node as the server according to the status information of each node and the pre-set allocation policy to allocate the Socket connection request; S4. Establish a Socket connection request between the node acting as the server and the node acting as the client, and determine the routing path. Further, the following steps are also included: S5. Data and status synchronization are performed among nodes based on the distributed consistency protocol; S6. Connection fault tolerance and connection expansion are performed among nodes.

[0008] Further, the specific steps of step S1 are as follows: S11. Split the centralized server into several nodes, and configure each node to support Socket connection requests; S12. Configure each node to support the dynamic establishment and disconnection of Socket connection requests.

[0009] Further, the specific steps of step S2 are as follows: S21. Configure the working mode of the registration center; When it is the active mode, go to step S22; When it is the passive mode, go to step S23; S22. The registration center regularly obtains the status information of each node, and enters step S3; S23. Each node regularly reports the status information to the registration center; the status information includes whether the status is normal, the connection status, and the response time.

[0010] Further, in step S23, when there is a newly started node, the newly started node reports the registration information to the registration center; the registration information includes the IP address, port, and load capacity.

[0011] Further, the specific steps of step S3 are as follows: S31. The load balancer listens for the Socket connection request from the node acting as the client; S32. The load balancer obtains the pre-set allocation policy; When it is the round-robin policy, go to step S33; When it is the least-connections policy, go to step S34; When it is the fastest-response policy, go to step S35; S33. The load balancer determines the target node according to the set cyclic order, selects the target node as the server, and enters step S36; S34. The load balancer obtains the status information of each node, identifies the node with the least number of existing connections as the target node, selects the target node as the server, and proceeds to step S36; S35. The load balancer obtains the status information of each node, identifies the node with the fastest response time as the target node, and selects the target node as the server; S36. The load balancer distributes the Socket connection requests to each node serving as the server.

[0012] Further, the specific steps of step S4 are as follows: S41. The node on the server side establishes a Socket connection with the node on the client side; S42. The node on the client side initiates data transmission to the node on the server side; S43. The node on the server side parses the transmitted data to determine the data processing mode; When it is the in-node transmission mode, proceed to step S44; When it is the out-of-node transmission mode, proceed to step S45; S44. The node on the server side determines the target module according to the type of the transmitted data, and transmits the data to the target module inside the node on the server side, and proceeds to step S5; S45. The node on the server side determines the routing path of the server node with the current node as the client node according to the target node of the data transmission, and performs data transmission.

[0013] Further, the specific steps of step S5 are as follows: S51. Transaction consistency is unified among nodes through a distributed transaction coordination mechanism; S52. Data consistency synchronization is performed among nodes through distributed storage.

[0014] Further, the specific steps of step S6 are as follows: S61. When there is a faulty node, the load balancer reselects a node according to the status of each node for the distribution of Socket requests; S62. When the node is a functional node, monitor the node status, and when the node status is abnormal, expand new nodes for function replacement.

[0015] In a second aspect, the present invention provides a distributed Socket communication device, including: A distributed node construction module, configured to construct a plurality of distributed nodes supporting Socket connection requests based on a centralized server; A node status acquisition module, configured to enable a registration center to obtain the status information of each node; A connection request allocation module, configured to enable a load balancer to receive a Socket connection request from a node acting as a client, and select a node as a server according to the status information of each node and a preset allocation policy to allocate the Socket connection request; A connection request establishment module, configured to establish a Socket connection request between the node acting as the server and the node acting as the client, and determine a routing path.

[0016] Furthermore, it further includes: A status synchronization module, configured to perform data and status synchronization among nodes based on a distributed consistency protocol; A connection fault tolerance and expansion module, configured to perform connection fault tolerance and connection expansion among nodes.

[0017] In a third aspect, the present invention provides a storage medium, wherein instructions are stored in the storage medium, and when the instructions run on a computer, the computer is caused to execute the method described in the first aspect above.

[0018] The beneficial effects of the present invention are as follows: The distributed Socket communication method, device and medium provided by the present invention are a scalable distributed communication architecture for large-scale network applications, enhancing the concurrent processing ability and data transmission efficiency of the system, and providing good fault tolerance ability to ensure the stability of communication.

[0019] In addition, the design principle of the present invention is reliable, the structure is simple, and it has a very wide application prospect.

[0020] It can be seen that, compared with the prior art, the present invention has prominent substantial features and significant progress, and the beneficial effects of its implementation are also obvious. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can also be obtained based on these drawings without creative efforts.

[0022] Figure 1 It is a schematic flowchart of an embodiment of the distributed Socket communication method of the present invention.

[0023] Figure 2 It is a schematic flowchart of another embodiment of the distributed Socket communication method of the present invention.

[0024] Figure 3 It is a schematic diagram of the distributed Socket communication device of the present invention. Detailed implementation manners

[0025] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0026] Embodiment 1: As Figure 1 shown, the present invention provides a distributed Socket communication method, including the following steps: S1. Based on a centralized server, construct a number of distributed nodes that support Socket connection requests; S2. The registration center obtains the status information of each node; S3. The load balancer receives the Socket connection requests of the nodes acting as clients, and selects a node as the server according to the status information of each node and the preset allocation policy to allocate the Socket connection requests; S4. Establish a Socket connection request between the node on the server side and the node on the client side, and determine the routing path; S5. Data and status synchronization are performed among the nodes based on the distributed consistency protocol; S6. Connection fault tolerance and connection expansion are performed among the nodes.

[0027] Embodiment 2: As Figure 2 shown, the present invention provides a distributed Socket communication method, including the following steps: S1. Based on a centralized server, construct a number of distributed nodes that support Socket connection requests; The specific steps of step S1 are as follows: S11. Split the centralized server into a number of nodes, and configure each node to support Socket connection requests; S12. Configure the dynamic establishment and disconnection of Socket connection requests supported by each node; S2. The registration center obtains the status information of each node; The specific steps of step S2 are as follows: S21. Configure the working mode of the registration center; When it is the active mode, go to step S22; When it is the passive mode, go to step S23; S22. The registration center regularly obtains the status information of each node, and enters step S3; S23. Each node regularly reports its status information to the registration center; the status information includes whether the status is normal, the connection status, and the response time; when there is a newly started node, the newly started node reports its registration information to the registration center; the registration information includes the IP address, port, and load capacity. S3. The load balancer receives the Socket connection request from the node acting as the client and selects a node as the server according to the status information of each node and the pre-set allocation strategy to allocate the Socket connection request; the specific steps of step S3 are as follows: S31. The load balancer listens for the Socket connection request from the node acting as the client. S32. The load balancer obtains the pre-set allocation strategy. When it is the round-robin strategy, go to step S33. When it is the least-connection strategy, go to step S34. When it is the fastest-response strategy, go to step S35. S33. The load balancer determines the target node according to the set cyclic order, selects the target node as the server, and enters step S36. S34. The load balancer obtains the status information of each node, identifies the node with the least number of existing connections as the target node, selects the target node as the server, and enters step S36. S35. The load balancer obtains the status information of each node, identifies the node with the fastest response time as the target node, and selects the target node as the server. S36. The load balancer allocates the Socket connection request to each node acting as the server. S4. Establish a Socket connection request between the node on the server side and the node on the client side, and determine the routing path; the specific steps of step S4 are as follows: S41. The node on the server side establishes a Socket connection with the node on the client side. S42. The node on the client side starts data transmission to the node on the server side. S43. The node on the server side parses the transmitted data and determines the data processing mode. When it is the in-node transmission mode, go to step S44. When it is the out-of-node transmission mode, go to step S45. S44. The node on the server side determines the target module according to the type of the transmitted data, and transmits the data to the target module inside the node on the server side, and enters step S5. S45. The node on the server side determines the routing path for data transmission with the current node as the client node and the node on the server side as the target node for data transmission. S5. Data and status synchronization are performed among nodes based on a distributed consistency protocol; the specific steps of step S5 are as follows: S51. Transaction consistency is unified among nodes through a distributed transaction coordination mechanism; S52. Data consistency synchronization is performed among nodes through distributed storage; S6. Connection fault tolerance and connection expansion are performed among nodes; the specific steps of step S6 are as follows: S61. When there is a faulty node, the load balancer reselects a node based on the status of each node to allocate Socket requests; S62. When the node is a functional node, the node status is monitored, and when the node status is abnormal, a new node is extended for function replacement.

[0028] It should be noted that the distributed Socket communication method of the present invention can be a distributed system based on a microservices architecture, and each microservices instance can be regarded as an independent communication node; these nodes provide a unified API interface externally and can be deployed and managed on a containerization platform such as Kubernetes; the communication between nodes can be achieved through a lightweight message queue such as RabbitMQ, or through a remote procedure call RPC framework such as the gRPC framework; At startup, each microservices instance registers its own address and service information with a service discovery component, such as Consul or Eureka; the service registration information includes service name, service IP, port number, health status, etc.; a load balancer such as Nginx or Envoy listens for requests from clients and uses the information of the service discovery component to determine which microservices instance should handle the request; the request allocation policy can be based on the current load, response time, or other defined metrics of each instance; the microservices instance selected by the load balancer will establish a Socket connection and execute the corresponding business logic according to the request data; data routing may involve service link tracing to ensure that requests can be correctly forwarded among various microservices instances; to achieve transaction consistency, a distributed transaction coordination mechanism such as the two-phase commit protocol or the event-based SAGA pattern can be adopted; status synchronization can be completed through a distributed cache such as Redis or Apache Kafka to maintain data consistency among nodes; when a certain microservices instance fails, the load balancer will automatically redirect the request to other healthy instances to achieve failover; a container orchestration platform such as Kubernetes can be adopted to monitor the service status and automatically restart a new instance to replace it when the service instance fails.

[0029] It should be noted that the distributed Socket communication method of the present invention is a P2P-based network, where each node is both a client and a server; the communication between nodes does not depend on a central node but is carried out in a distributed manner; nodes use distributed hash table technology such as the Kademlia protocol to achieve the discovery and information exchange of other nodes in the network; when a node joins the network, it broadcasts its existence to neighboring nodes and obtains network topology information; nodes dynamically establish and disconnect Socket connections according to network conditions and data requirements; through adaptive network measurement, nodes can select the best data transmission route; when data is transmitted between nodes, a data verification mechanism similar to that of blockchain can be adopted to ensure the integrity and correctness of the data; in order to prevent malicious behavior, a node reputation system can be implemented to record the behavior of nodes and select trusted transmission paths accordingly; data storage can use a distributed file system to achieve data sharing and persistence between nodes; the maintenance of data consistency can use technologies such as CRDTs or version vectors; the P2P network can self-repair. When a node fails, the network automatically reorganizes and the data is transmitted through other paths; network performance optimization can use machine learning algorithms to predict network traffic and adjust data routing strategies.

[0030] Through the above specific implementation manners based on the microservice architecture and the P2P network, the present invention can effectively improve the efficiency of data transmission and the scalability of the system, and at the same time ensure the high availability and data consistency of the system.

[0031] Embodiment 3: As Figure 3 shown, the present invention provides a distributed Socket communication device, including: A distributed node construction module for constructing a number of distributed nodes that support Socket connection requests based on a centralized server; A node status acquisition module for enabling a registration center to acquire the status information of each node; A connection request allocation module for enabling a load balancer to receive Socket connection requests from nodes acting as clients and select a node as the server according to the status information of each node and a preset allocation strategy for the allocation of Socket connection requests; A connection request establishment module for establishing a Socket connection request between the node acting as the server and the node acting as the client and determining a routing path.

[0032] Embodiment 4: The present invention provides a storage medium, wherein instructions are stored in the storage medium, and when they run on a computer, the computer is made to execute the method described in Embodiment 1 or Embodiment 2 above.

[0033] Although the present invention has been described in detail by reference to the accompanying drawings and in conjunction with the preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, those of ordinary skill in the art can make various equivalent modifications or substitutions to the embodiments of the present invention, and all such modifications or substitutions should be within the scope of the present invention / Any person skilled in the art within the technical scope disclosed by the present invention can easily think of changes or substitutions, which should all be covered by the protection scope of the present invention.

Claims

1. A distributed Socket communication method, characterized in that: The steps include: S1. Build several distributed nodes that support Socket connection requests based on a centralized server; S2. The registration center obtains the status information of each node; S3. The load balancer receives the Socket connection request from the node as the client, and selects a node as the server to distribute the Socket connection request according to the status information of each node and the pre-set allocation strategy; S4. Establish a Socket connection request between the server node and the client node, and determine the routing path.

2. The distributed Socket communication method according to claim 1, characterized in that: The following steps are also included: S5. Data and status synchronization between nodes based on distributed consistency protocol; S6. Perform connection fault tolerance and connection expansion between nodes.

3. The distributed Socket communication method according to claim 2, characterized in that: The specific steps of step S1 are as follows: S11. Split the centralized server into several nodes, and configure each node to support Socket connection requests; S12. Configure each node to support dynamic establishment and disconnection of Socket connection requests.

4. The distributed Socket communication method according to claim 3, characterized in that: The specific steps of step S2 are as follows: S21. Configure the working mode of the registration center; When it is in active mode, go to step S22; When it is in passive mode, go to step S23; S22. The registration center periodically obtains status information of each node status and proceeds to step S3; S23. Each node reports status information to the registration center at regular intervals; the status information includes whether the status is normal, connection status, and response time.

5. The distributed Socket communication method according to claim 4, characterized in that: The specific steps of step S3 are as follows: S31. The load balancer monitors the socket connection request of the node acting as the client; S32. The load balancer obtains a preset allocation strategy; When the round-robin strategy is adopted, the process goes to step S33; When the least connection strategy is used, go to step S34; When the fastest response strategy is selected, proceed to step S35; S33. The load balancer determines the target node according to the set loop order, selects the target node as the server, and proceeds to step S36; S34. The load balancer obtains the status information of each node and identifies the node with the least number of existing connections as the target node, selects the target node as the server, and proceeds to step S36; S35. The load balancer obtains the status information of each node and identifies the node with the fastest response time as the target node, and selects the target node as the server; S36. The load balancer distributes the Socket connection request to each node that serves as the server.

6. The distributed Socket communication method according to claim 5, characterized in that: The specific steps of step S4 are as follows: S41. The server node establishes a Socket connection with the client node; S42. The client node starts data transmission to the server node; S43. The server node parses the transmitted data and determines the data processing mode; When it is the intra-node transmission mode, go to step S44; When it is the node-out transmission mode, go to step S45; S44. The server node determines the target module according to the data type transmitted, transmits the data to the target module inside the server node, and proceeds to step S5; S45. The server node determines, according to the target node for data transmission, a routing path of the server node with the current node as the client node for data transmission.

7. The distributed Socket communication method according to claim 2, characterized in that: The specific steps of step S5 are as follows: S51. The nodes use a distributed transaction coordination mechanism to unify transaction consistency; S52. Data consistency is synchronized between nodes through distributed storage.

8. The distributed Socket communication method according to claim 2, characterized in that: The specific steps of step S6 are as follows: S61. When there is a faulty node, the load balancer reselects a node to distribute the Socket request according to the status of each node; S62. When the node is a functional node, monitor the node status, and when the node status is abnormal, expand a new node to replace the function.

9. A distributed Socket communication device, characterized in that: include: Distributed node building module, used to build several distributed nodes supporting Socket connection requests based on a centralized server; The node status acquisition module is used to enable the registration center to obtain the status information of each node; The connection request allocation module is used to enable the load balancer to receive the Socket connection request of the node as the client, and select the node as the server to allocate the Socket connection request according to the status information of each node and the preset allocation strategy; The connection request establishment module is used to establish a Socket connection request between the server node and the client node and determine the routing path.

10. A storage medium, characterized in that: The storage medium stores instructions, which, when executed on a computer, enable the computer to execute the method described in any one of claims 1 to 8.