Point-to-point connection method, device and storage medium based on network address translation

By comparing the communication paths between the terminal device and the server, determining the path aggregation point and creating a connection request, the problem of difficulty in establishing a P2P connection in the NAT loopback is solved, and point-to-point connection is realized in the case of NAT loopback.

CN119299462BActive Publication Date: 2025-03-21ZHEJIANG DAHUA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411830072.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-12
Publication Date
2025-03-21
Estimated Expiration
2044-12-12

AI Technical Summary

Technical Problem

The existence of NAT makes it difficult for terminal devices located in different NAT environments to directly establish P2P connections, especially in the case of NAT loopback. If the NAT device does not support Hairpin technology, it will block the P2P penetration behavior of terminal devices under the same NAT.

Method used

By comparing the first communication path between the first terminal and the server end and the second communication path between the second terminal and the server end, it is determined whether there is a path aggregation point between the two. If there is a path aggregation point and the external network port of the first terminal is the same as the local port, a connection request is created based on the path aggregation point, and the connection request is sent to the second terminal through the server to realize a point-to-point connection.

Benefits of technology

In the case of NAT loopback, a point-to-point connection between different terminals was successfully established, which solved the P2P penetration problem when NAT devices do not support Hairpin technology.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119299462B_ABST
    Figure CN119299462B_ABST
Patent Text Reader

Abstract

The present application discloses a point-to-point connection method, device and storage medium based on network address translation, the method comprising: comparing a first communication path between a first terminal and a server end with a second communication path between a second terminal and a server end, determining a path convergence point between the first communication path and the second communication path; in response to the first external network port of the first terminal on the server end being the same as the first local port of the first terminal, creating a connection request based on the path convergence point; sending the connection request to the second terminal through the server end, so that the second terminal returns a connection response to the first terminal through the server end based on the received connection request; in response to the received connection response, sending penetration connection data to the second terminal according to the connection response for point-to-point connection. The above scheme can successfully establish a point-to-point connection between different terminals in a scenario based on network address translation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication technology, and in particular to a point-to-point connection method, device and storage medium based on network address translation. Background Art

[0002] In modern Internet communications, P2P (Peer-to-Peer) technology is widely used due to its efficient data transmission capabilities and decentralized network architecture, especially in the fields of file sharing, real-time audio and video communications, and online games.

[0003] However, the existence of NAT (Network Address Translation) has brought major challenges to the implementation of P2P technology. NAT is a technology that converts private IP addresses and public IP addresses in the network. It allows multiple internal devices to share a public IP address to access the Internet, which effectively saves public IP resources and also provides additional security protection for home and corporate networks.

[0004] However, the existence of NAT makes it difficult for terminal devices in different NAT environments to directly establish P2P connections, especially when these terminal devices are in the same public NAT network environment, that is, when there is a NAT loop. If the NAT device does not support Hairpin (port backflow) technology, the P2P penetration behavior of terminal devices under the same NAT will be blocked, which makes it impossible for terminal devices in different intranets under the same NAT to establish P2P connections. Summary of the invention

[0005] The present application at least provides a point-to-point connection method, apparatus, device and computer-readable storage medium based on network address translation.

[0006] In a first aspect, the present application provides a point-to-point connection method based on network address translation, which is applied to a first terminal, and the first terminal communicates with a second terminal through a server, comprising: comparing a first communication path between the first terminal and the server with a second communication path between the second terminal and the server, and determining whether there is a path convergence point between the first communication path and the second communication path, and the second communication path is obtained based on the server; in response to the existence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server is the same as the first local port of the first terminal, creating a connection request based on the path convergence point; sending the connection request to the second terminal through the server, so that the second terminal returns a connection response to the first terminal through the server based on the received connection request; in response to the received connection response, sending penetration connection data to the second terminal according to the connection response for point-to-point connection.

[0007] In one embodiment, the first communication path between the first terminal and the server end is compared with the second communication path between the second terminal and the server end to determine whether there is a path convergence point between the first communication path and the second communication path, including: obtaining a first LAN address set and a second LAN address set, the first LAN address set including the LAN address of the routing device in the first communication path, and the second LAN address set including the LAN address of the routing device in the second communication path; comparing the first LAN address set and the second LAN address set, and determining the routing devices with the same LAN address as the path convergence point.

[0008] In one embodiment, the comparing the first LAN address set and the second LAN address set, and determining the routing device with the same LAN address as the path convergence point, includes: comparing the first LAN address set and the second LAN address set to obtain the target routing device with the same LAN address in each routing device; determining whether the target routing device is a non-leaf node in the current communication network; if so, determining the target routing device as the path convergence point.

[0009] In one embodiment, in response to the presence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server side is the same as the first local port of the first terminal, before creating a connection request based on the path convergence point, the method further includes: determining whether the first external network port obtained from the server side is the same as the first local port in the local socket of the first terminal; after determining whether the first external network port obtained from the server side is the same as the first local port bound to the local socket, the method further includes: in response to the first external network port and the first local port being different, creating a new socket and obtaining the current first external network port from the server side for comparison, the new socket including the current first local port, until the current first local port and the current first external network port are the same.

[0010] In one embodiment, the creation of a connection request based on the path convergence point includes: determining a first local address based on the address information and port information bound to the local socket of the first terminal; determining a first intermediate address based on the address information and port information of the lower-level routing node of the path convergence point in the current communication network; determining a first public network address based on the external network address and port information of the first terminal obtained from the server; creating the connection request, the connection request carrying candidate address information of the first terminal, the candidate address information including at least one of the first local address, the first intermediate address and the first public network address.

[0011] In one embodiment, in response to the received connection response, sending penetration connection data to the second terminal according to the connection response to establish a point-to-point connection includes: parsing the connection response to obtain candidate address information of the second terminal carried by the connection response; and selecting target address information from each candidate address information in turn according to the priority of each candidate address information to send the penetration connection data until the first terminal and the second terminal establish a point-to-point connection.

[0012] In one embodiment, before comparing the first communication path between the first terminal and the server end with the second communication path between the second terminal and the server end to determine whether there is a path convergence point between the first communication path and the second communication path, the method further includes: identifying the network address translation type of the first communication path and the network address translation type of the second communication path; in response to the network address translation types of the first communication path and the second communication path being cone-type, and the first public network address of the first terminal on the server end and the second public network address of the second terminal on the server end being consistent, determining that there is a network address translation loop in the current communication network where the first terminal and the second terminal are located; after determining that there is a network address translation loop between the first terminal and the second terminal, the method further includes: comparing the first communication path with the second communication path to obtain the path convergence point.

[0013] The second aspect of the present application provides a point-to-point connection method based on network address translation, the method is applied to a second terminal, the second terminal communicates with a first terminal through a server side, the method includes: in response to a connection request received from the server side, parsing the connection request to obtain the aggregation address information of the path convergence point carried by the connection request; determining the address information of the lower-level routing node of the path convergence point in the current communication network according to the aggregation address information, and determining the second intermediate address according to the address information of the lower-level routing node; creating the connection response, the connection response carries the candidate address information of the second terminal, the candidate address information includes at least one of the second local address of the second terminal, the second intermediate address and the second public network address of the second terminal on the server side; sending the connection response to the server side, so that the server side forwards the received connection response to the first terminal.

[0014] The third aspect of the present application provides a point-to-point connection device based on network address translation, including: a path comparison module, used to compare the first communication path between the first terminal and the server end with the second communication path between the second terminal and the server end, and determine whether there is a path convergence point between the first communication path and the second communication path, and the second communication path is obtained based on the server end; a request creation module, used to respond to the existence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server end and the first local port of the first terminal are the same, and create a connection request based on the path convergence point; a request sending module, used to send the connection request to the second terminal through the server end, so that the second terminal returns a connection response to the first terminal through the server end based on the received connection request; a penetration connection module, used to respond to the received connection response, and send penetration connection data to the second terminal according to the connection response to perform a point-to-point connection.

[0015] The fourth aspect of the present application also provides a point-to-point connection device based on network address translation, including: a request parsing module, which is used to respond to the connection request sent by the server end, parse the connection request, and obtain the aggregation address information of the path convergence point carried by the connection request; an address determination module, which is used to determine the address information of the lower-level routing node of the path convergence point in the current communication network according to the aggregation address information, and determine the second intermediate address according to the address information of the lower-level routing node; a response creation module, which is used to create the connection response in response to the second external network port of the second terminal on the server end and the second local port of the second terminal being the same, and the connection response carries the candidate address information of the second terminal, and the candidate address information includes at least one of the second local address of the second terminal, the second intermediate address and the second public network address of the second terminal on the server end; a response sending module, which is used to send the connection response to the server end, so that the server end forwards the received connection response to the first terminal.

[0016] A fifth aspect of the present application provides an electronic device, including a memory and a processor, wherein the processor is used to execute program instructions stored in the memory to implement the above-mentioned point-to-point connection method based on network address translation.

[0017] A sixth aspect of the present application provides a computer-readable storage medium having program instructions stored thereon, which implement the above-mentioned point-to-point connection method based on network address translation when the program instructions are executed by a processor.

[0018] The above scheme determines whether there is a path convergence point between the first communication path and the second communication path by comparing the first communication path between the first terminal and the server end with the second communication path between the second terminal and the server end. In response to the existence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server end is the same as the first local port of the first terminal, it indicates that the first terminal and the second terminal can establish an interactive connection based on the address information of the path convergence point of the communication paths of the two terminals, and thus a connection request is created based on the path convergence point. The connection request is sent to the second terminal through the server end, so that the second terminal returns a connection response to the first terminal through the server end based on the received connection request. In response to the received connection response, it can be indicated that network penetration can be performed between the first terminal and the second terminal, and penetration connection data is sent to the second terminal according to the connection response to perform a point-to-point connection. In this way, a point-to-point connection between different terminals can be successfully established in a scenario based on network address translation.

[0019] 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 application. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and are used together with the specification to illustrate the technical solution of the present application.

[0021] Figure 1 It is a flowchart of an exemplary embodiment of a point-to-point connection method based on network address translation of the present application;

[0022] Figure 2 This is a schematic diagram of an exemplary application scenario in the point-to-point connection method based on network address translation of the present application;

[0023] Figure 3 This is an exemplary process sequence diagram of the point-to-point connection method based on network address translation of the present application;

[0024] Figure 4 It is an exemplary overall flow chart of the point-to-point connection method based on network address translation of the present application;

[0025] Figure 5 is another exemplary overall flow chart of the point-to-point connection method based on network address translation of the present application;

[0026] Figure 6 is a block diagram of a point-to-point connection device based on network address translation shown in an exemplary embodiment of the present application;

[0027] Figure 7 It is a structural schematic diagram of an embodiment of the electronic device of the present application;

[0028] Figure 8 It is a structural diagram of an embodiment of a computer-readable storage medium of the present application. DETAILED DESCRIPTION

[0029] The scheme of the embodiment of the present application is described in detail below in conjunction with the drawings of the specification.

[0030] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, interfaces, and technologies are provided to facilitate a thorough understanding of the present application.

[0031] The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the objects associated before and after are in an "or" relationship. In addition, "many" in this article means two or more than two. In addition, the term "at least one" in this article means any combination of at least two of any one or more of a plurality of, for example, including at least one of A, B, and C, can mean including any one or more elements selected from the set consisting of A, B, and C.

[0032] For ease of understanding, one of the applicable scenarios of the present application is now exemplarily described.

[0033] In modern Internet communications, P2P (Peer-to-Peer) technology is widely used due to its efficient data transmission capabilities and decentralized network architecture, especially in the fields of file sharing, real-time audio and video communications, and online games.

[0034] However, the existence of NAT (Network Address Translation) has brought major challenges to the implementation of P2P technology. NAT is a technology that converts private IP addresses and public IP addresses in the network. It allows multiple internal devices to share a public IP address to access the Internet, which effectively saves public IP resources and also provides additional security protection for home and corporate networks.

[0035] However, the existence of NAT makes it difficult for terminal devices in different NAT environments to directly establish P2P connections, especially when these terminal devices are in the same public NAT network environment, that is, when there is a NAT loopback, if the NAT device does not support Hairpin (port backflow) technology, it will block the P2P penetration behavior of the terminal devices under the same NAT, which makes it impossible for terminal devices in different intranets under the same NAT to establish P2P connections. Business communication can only be completed through platform relay forwarding and other methods, so how to achieve P2P connection establishment under NAT loopback when the public network NAT device does not support Hairpin technology is an urgent problem to be solved.

[0036] It should be noted that the NAT loopback problem usually occurs when the terminal device is connected to the wireless hotspot of the router. For example, when a user uses the first terminal to connect to the wireless hotspot of router 1 to access the second terminal connected to router 2, the first terminal and the second terminal are in different NAT networks, but their public network NAT devices (router 1 and router 2) reuse the same network. When the terminal devices send penetration handshake packets to the same public network IP address to establish a P2P connection, a NAT loopback problem will occur. The essence of the NAT loopback problem is that the NAT device does not support data flow forwarding from LAN->WAN->LAN, and most NAT devices default to cone NAT type.

[0037] See also Figure 1 , Figure 1 1 is a flowchart of an exemplary embodiment of the point-to-point connection method based on network address translation of the present application. The method can be applied to a first terminal, and the first terminal communicates with a second terminal through a server. Figure 2 As shown, Figure 2 This is a schematic diagram of an exemplary application scenario in the point-to-point connection method based on network address translation of the present application. Specifically, it may include the following steps:

[0038] Step S110, comparing a first communication path between a first terminal and a server with a second communication path between a second terminal and a server, determining whether there is a path convergence point between the first communication path and the second communication path, the second communication path being obtained based on the server.

[0039] It should be noted that the first terminal and the second terminal of the present application may include but are not limited to terminal devices such as mobile phones, computers, smart watches, smart home appliances, etc. The type of the first terminal and the type of the second terminal may be the same or different. In actual application scenarios, there may be one or more first terminals and second terminals, and there may also be a third terminal, a fourth terminal, etc. in the current communication network, which are not limited here. For ease of understanding and explanation, the first terminal is mainly used as the requesting end in the connection process in this application, and the second terminal is used as the responding end in the connection process as an example for explanation, but it is not limited to the second terminal as the requesting end and the first terminal as the responding end in the actual application scenario, which is not repeated here.

[0040] The server side of the present application refers to the platform server side that provides communication services for terminal devices (such as the first terminal and the second terminal). Exemplarily, the server side of the present application can provide services including but not limited to application services, STUN services (Session Traversal Utilities for NAT) and platform signaling services. Among them, the STUN service is a network protocol that aims to solve real-time communication problems in a NAT environment. The STUN protocol allows the client (terminal) behind the NAT device to discover its public network visible address and determine the type of NAT, thereby helping the terminal device to establish a direct connection. As a result, the server side can be responsible for the signaling transmission between terminal devices, the acquisition of the external network IP and port after the terminal device exits NAT, and the storage of network information resources of the terminal device, etc. according to the above services.

[0041] The terminal device of the present application can also implement network segment detection technology based on traceroute, LLDP and other tracking routing tools to obtain the LAN port (Local Area Network) IP addresses of different routing nodes in the communication path between the terminal device and the server; it can also obtain the external network IP and port after the export NAT based on the STUN service of the server; it can also complete the exchange of P2P connection requests and response messages between the first terminal and the second terminal based on the platform signaling service.

[0042] It should also be noted that the first terminal communicates with the server through the first communication path, and the first communication path may include one or more routing nodes (routers), which can also be called NAT devices. Similarly, the second terminal communicates with the server through the second communication path, and the second communication path may also include one or more routing nodes (routers).

[0043] Therefore, by comparing the first communication path and the second communication path, it is possible to determine whether there is a path convergence point between the first communication path and the second communication path, that is, to determine whether there is the same NAT device in the first communication path and the second communication path.

[0044] Step S120, in response to the presence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server side is the same as the first local port of the first terminal, creating a connection request based on the path convergence point.

[0045] In conjunction with the above steps, the first external network port can be obtained by the first terminal through the STUN service provided by the server. The first local port can be obtained by the first terminal from its own network information (for example, the port number bound to the local socket). The connection request in this step refers to a request for establishing a P2P connection.

[0046] It should be noted that if the first external network port of the first terminal on the server side is the same as the first local port of the first terminal, it can represent the consistency of the mapping ports of each NAT device in the first communication path, that is, there will be no NAT device in the first communication path that changes the local port of the first terminal (the same applies to the second communication path), so that the first terminal and the second terminal can complete the ICE (Interactive Connectivity Establishment) process of both parties based on the network information of a NAT device in the communication path.

[0047] Therefore, in response to the existence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server side is the same as the first local port of the first terminal, a connection request can be created based on the path convergence point, that is, an attempt can be made to create a P2P connection between the first terminal and the second terminal based on the network information related to the path convergence point.

[0048] Step S130: sending a connection request to the second terminal through the server, so that the second terminal returns a connection response to the first terminal through the server based on the received connection request.

[0049] In conjunction with the above steps, after the first terminal creates a connection request, the connection request can be sent to the server, and then the server forwards the connection request to the second terminal through the platform signaling service provided by the server.

[0050] For the second terminal, it can respond accordingly based on the connection request and generate a response to the connection request (i.e., a connection response), thereby indicating whether the second terminal agrees to establish a P2P connection with the first terminal or not through the connection response. The second terminal then sends the connection response to the server, and the server then forwards the received connection response to the first terminal.

[0051] Step S140, in response to the received connection response, transmitting the penetration connection data to the second terminal according to the connection response to establish a point-to-point connection.

[0052] In combination with the above steps, after receiving the connection response, if the first terminal learns from the connection response that the second terminal agrees to establish a P2P connection with the first terminal, the first terminal can send penetration connection data to the second terminal for a point-to-point connection based on the information carried in the connection response.

[0053] Among them, the penetration connection data can also be called a penetration handshake packet. For details, please refer to the three-way handshake principle for establishing a communication connection, etc., which will not be elaborated here.

[0054] It can be seen that the present application determines whether there is a path convergence point between the first communication path and the second communication path by comparing the first communication path between the first terminal and the server end with the second communication path between the second terminal and the server end. In response to the existence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server end is the same as the first local port of the first terminal, it is characterized that the first terminal and the second terminal can establish an interactive connection based on the address information of the path convergence point of the communication paths of the two terminals, and thus a connection request is created based on the path convergence point. The connection request is sent to the second terminal through the server end, so that the second terminal returns a connection response to the first terminal through the server end based on the received connection request. In response to the received connection response, it can be characterized that the network penetration can be performed between the first terminal and the second terminal, and the penetration connection data is sent to the second terminal according to the connection response for point-to-point connection. In this way, a point-to-point connection between different terminals can be successfully established in a scenario based on network address translation.

[0055] Based on the above embodiment, the embodiment of the present application describes the steps of comparing the first communication path between the first terminal and the server with the second communication path between the second terminal and the server to determine whether there is a path convergence point between the first communication path and the second communication path. Specifically, the method of this embodiment includes the following steps:

[0056] Obtain a first LAN address set and a second LAN address set, the first LAN address set including LAN addresses of routing devices in a first communication path, and the second LAN address set including LAN addresses of routing devices in a second communication path; compare the first LAN address set and the second LAN address set, and determine routing devices with the same LAN address as path convergence points.

[0057] In conjunction with the above-mentioned embodiment, one or more NAT devices may exist in the first communication path, and one or more NAT devices may also exist in the second communication path. Therefore, the first terminal may obtain the LAN port IP address of each NAT device in the first communication path to obtain the first LAN address set, and obtain the LAN port IP address of each NAT device in the second communication path to obtain the second LAN address set.

[0058] Furthermore, the first terminal compares the IP address in the first LAN address set with the IP address in the second LAN address set. If the same IP address exists, it can be determined that the same NAT device exists between the first communication path and the second communication path, that is, there is a path convergence point. If the same IP address does not exist, it can be determined that there is no path convergence point between the first communication path and the second communication path, and other address information is used for P2P connection. Among them, if there is an identical IP address, the node where the NAT device corresponding to the LAN port IP address is located is determined as the path convergence point. If there are multiple identical IP addresses, the time when each identical IP address is successfully matched is compared, and the node where the NAT device corresponding to the identical IP address that is first successfully matched can be selected as the path convergence point.

[0059] Exemplarily, the first terminal can obtain the LAN port IP addresses of each NAT device between itself and the server side through network segment detection technology such as traceroute command, and obtain the first LAN address set. Similarly, the second terminal can also obtain the LAN port IP addresses of each NAT device between it and the server side through network segment detection technology such as traceroute command, and obtain the second LAN address set. Among them, the first terminal and / or the second terminal can also periodically report the LAN port IP addresses of each NAT device in their respective communication paths to the server side, so that the first terminal can directly obtain the second LAN address set from the server side when obtaining it, thereby improving the processing efficiency of the present application.

[0060] Based on the above embodiments, the present embodiment of the present application describes the steps of comparing the first LAN address set with the second LAN address set and determining the routing devices with the same LAN address as the path convergence point. Specifically, the method of this embodiment includes the following steps:

[0061] Compare the first LAN address set and the second LAN address set to obtain a target routing device with the same LAN address in each routing device; determine whether the target routing device is a non-leaf node in the current communication network; if so, determine the target routing device as a path convergence point.

[0062] In conjunction with the foregoing embodiment, the first LAN address set and the second LAN address set are compared, mainly to compare the LAN port IP addresses of each NAT device in the first LAN address set with the LAN port IP addresses of each NAT device in the second LAN address set, and then obtain the NAT device with the same LAN port IP address, that is, the target routing device.

[0063] Combination Figure 2 To illustrate, the communication network of each terminal is composed of the following Figure 2 The tree network topology diagram shown. In the tree network topology, the LAN port IP address set of the first terminal is routing device 5, routing device 2, and routing device 1, and the LAN port IP address set of the second terminal is routing device 3 and routing device 1. Thus, the first terminal and the second terminal can complete the P2P connection process based on the LAN port network of routing device 1 at the path convergence point.

[0064] In addition, in order to prevent some special situations, when searching for path convergence points, in addition to determining the NAT device with the same LAN port IP address, this application also needs to determine whether the NAT device with the same LAN port IP address is a non-leaf node in the current communication network for each terminal.

[0065] Exemplarily, whether the NAT device is a non-leaf node can be determined by judging whether the NAT device has a lower-level routing node. If the NAT device has a lower-level routing node, the NAT device is determined to be a non-leaf node; otherwise, it is a leaf node.

[0066] Exemplarily, reference may be made to Table 1 below, which is the network information reported by different terminal devices and stored on the server side in the point-to-point connection method based on network address translation of the present application, which may at least include: the LAN port IP address of each NAT device in the communication path between each terminal and the server side, the NAT type of the network side where each terminal is located, and the external network IP address after its exit NAT.

[0067]

[0068] Among them, the NAT device LAN port IP address concentration can be to arrange each LAN port IP address in the order of NAT devices passed in the communication path from the terminal device to the server. That is, in each NAT device LAN port IP address concentration, the arrangement order of each LAN port IP address represents the order of NAT devices passed from the starting point to the end point of data transmission in the transmission path from each terminal to the server.

[0069] Therefore, taking Table 1 as an example, it can be obtained that the NAT device with the LAN port IP address of 192.168.10.1 in sequence number 1 is the subordinate route of the NAT device with the LAN port IP address of 192.168.0.1, and the NAT device with the LAN port IP address of 192.168.1.1 is the superior route of the NAT device with the LAN port IP address of 192.168.0.1.

[0070] It should be noted that if the target routing device is a leaf node in the current communication network on either side of the first terminal and / or the second terminal, that is, when the first terminal and / or the second terminal is directly connected to the target routing device, a P2P connection can be successfully established directly through the local addresses of both terminals without executing the process of obtaining the intermediate address.

[0071] Recombination Figure 2 As an example, if the NAT device at the path convergence point is a leaf node of a terminal device on one side, for example Figure 2 Routing device 3 and routing device 6 are removed, and routing device 2 and routing device 1 are leaf nodes of the second terminal and the third terminal respectively. The first terminal can establish P2P connections with the second terminal and the third terminal directly through their local addresses (i.e., first terminal->routing device 5->routing device 2->second terminal, first terminal->routing device 5->routing device 2->routing device 1->third terminal), without further determining the intermediate address according to the path convergence point.

[0072] On the basis of the above embodiment, the embodiment of the present application describes the steps before creating a connection request based on the path convergence point in response to the presence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server side and the first local port of the first terminal are the same. Specifically, the method of this embodiment includes the following steps:

[0073] Determine whether the first external network port obtained from the server side is the same as the first local port in the local socket of the first terminal; after determining whether the first external network port obtained from the server side is the same as the first local port bound to the local socket, the method also includes: in response to the first external network port and the first local port being different, create a new socket and obtain the current first external network port from the server side for comparison, the new socket including the current first local port, until the current first local port and the current first external network port are the same.

[0074] In combination with the above-mentioned embodiment, after determining that there is a path convergence point between the first communication path and the second communication path, it is also necessary to determine whether the first external network port of the first terminal on the server side and the first local port of the first terminal are the same, thereby analyzing the consistency of the mapping ports of each NAT device in the communication path of the terminal.

[0075] Among them, the method for judging whether the external network port and the local port are the same can be to determine whether the external network port of the terminal obtained from the server is the same as the port number bound to the local socket of the terminal. A socket may include two parts: an IP address and a port number. Each pair of processes communicating over the network needs to use a pair of sockets. The sockets used for communication between different processes are different, and the sockets can be used to distinguish data transmission between different processes. Therefore, in the communication process between the first terminal and the server, there is a corresponding socket, that is, the port number bound to the socket can be compared with the external network port obtained by the first terminal according to the STUN service of the server.

[0076] It should also be noted that in some special cases, if certain port numbers are occupied, the NAT device in the communication path may change the terminal's port number during data transmission, making the terminal's external network port and local port different, thereby affecting subsequent P2P connections.

[0077] Therefore, in the present application, if the first external network port and the first local port are different, a new socket needs to be created, and accordingly, the first external network port of the first terminal on the server may also change accordingly, so the current first external network port is obtained from the server and compared with the port number bound to the new socket. The new socket includes the current first local port until the current first local port and the current first external network port are the same, thereby ensuring the consistency of the mapping ports of each NAT device in the communication path of the terminal, and avoiding the NAT device occupying the port number of the terminal device data after NAT mapping, thereby causing NAT port jumping, resulting in the inability to accurately judge the NAT mapping port of the NAT device in the communication path during the implementation of the present application, so the local port of the terminal device must be the same as the external network port returned by the STUN service on the server.

[0078] Based on the above embodiment, the embodiment of the present application describes the steps of creating a connection request based on a path convergence point. Specifically, the method of this embodiment includes the following steps:

[0079] Determine a first local address based on the address information and port information bound to the local socket of the first terminal; determine a first intermediate address based on the address information and port information of the lower-level routing node of the path convergence point in the current communication network; determine a first public network address based on the external network address and port information of the first terminal obtained from the server side; create a connection request, the connection request carries the candidate address information of the first terminal, and the candidate address information includes at least one of the first local address, the first intermediate address and the first public network address.

[0080] In conjunction with the above-mentioned embodiment, when creating a connection request in the present application, the connection request needs to carry candidate address information so that the terminal receiving the connection request can make a P2P connection based on the candidate address information. Among them, the candidate address information of the present application may include at least one of a local address, an intermediate address, and a public network address. If there is only one type of candidate address information, a P2P connection is made based on the candidate address information; if there are multiple types of candidate address information, the target address information can be selectively selected from multiple candidate address information for P2P connection.

[0081] Exemplarily, taking the first terminal as an example, the first local address of the first terminal can be determined according to the IP address and port corresponding to its local socket; the first external network address of the first terminal can be determined according to the external network IP address and port of the first terminal returned by the STUN service on the server side; the first intermediate address of the first terminal can be determined according to the WAN port (Wide Area Network) IP address and external network port of the lower-level routing node of the path convergence point in the current communication network where the first terminal is located. In addition, the connection request can also include the LAN port IP address of the path convergence point.

[0082] After the first terminal creates the connection request, the connection request may be forwarded to the second terminal via the platform signaling service on the server side.

[0083] It should be noted that the WAN port IP address of the lower-level routing node of the path convergence point can be calculated based on the LAN port IP address of the path convergence point. For example: the pre-set subnet mask is 255.255.255.0 (fixed value of the LAN port subnet mask of a general network router), and the gateway address (i.e. the LAN port IP address after successful matching) and the subnet broadcast address are eliminated, and the remaining available host addresses are 253. After that, the terminal sends large data packets to the 253 addresses through the ping command and counts whether there are ping response messages and the average round-trip delay RTT of the ping process. The IP address that can successfully receive the ping response message and has the smallest RTT value in the ping command statistics is the WAN port IP address of the routing node.

[0084] Based on the above embodiment, the embodiment of the present application describes the steps of sending the penetration connection data to the second terminal for point-to-point connection in response to the received connection response according to the connection response. Specifically, the method of this embodiment includes the following steps:

[0085] Parse the connection response to obtain the candidate address information of the second terminal carried in the connection response; select the target address information from each candidate address information in turn according to the priority of each candidate address information to send the penetration connection data until the first terminal and the second terminal establish a point-to-point connection.

[0086] The connection response is information returned by the second terminal in response to the received connection request.

[0087] In combination with the above embodiment, after receiving the connection request sent by the first terminal, the second terminal will also adopt the same method as the first terminal (for details, please refer to the description of the above embodiment) to obtain the network information of its own network side and create a P2P connection response based on the information carried in the connection request.

[0088] Exemplarily, for the second terminal, the second terminal parses the connection request, obtains the LAN port IP address of the path convergence point, and calculates the WAN port IP address of the lower-level routing node of the path convergence point NAT device according to the calculation method provided in the aforementioned embodiment. The second device end can also compare its local port and the external network port in the same way. If they are different, a new socket is created and the external network port information is obtained from the platform STUN service until the local socket binding port number is the same as the external network port, thereby ensuring the consistency of the mapping ports of each NAT device in the communication path of the second terminal.

[0089] Then, the second terminal can construct a P2P connection response and return it to the first terminal through the server. The connection response carries the candidate address information of the second terminal. Similarly, the candidate address information can also include at least one of the IP address and port (local address) corresponding to the local socket, the external network IP and port (public network address) returned by the STUN service, and the WAN port IP address and external network port (intermediate address) of the lower-level routing node of the path convergence point.

[0090] Thus, the first terminal and the second terminal implement the exchange of candidate address information that can be used by both parties to establish a P2P connection based on the platform signaling service of the server.

[0091] Furthermore, for the first terminal, after receiving the connection response, the first terminal may establish a P2P connection according to the candidate address information of the second terminal parsed from the connection response.

[0092] Specifically, the candidate address information of the second terminal is similar to the candidate address information of the first terminal, and there may be one or more. In the present application, a corresponding priority can be set for each candidate address information. If there is one candidate address information, the first terminal establishes a P2P connection based on the candidate address information. If there are multiple candidate address information, the first terminal can select the target address information from each candidate address information in turn according to the priority of each candidate address information to send the penetration connection data until the first terminal and the second terminal establish a point-to-point connection.

[0093] For example, in this embodiment, the priority order of each candidate address information from high to low can be: local address, intermediate address and public network address. Therefore, when the local address, intermediate address and public network address are carried in the connection response, the first terminal can perform the ICE interaction process of NAT penetration according to the priority order of local address (IP address and port corresponding to the local socket), intermediate address (WAN port IP address and external network port of the lower routing node of the path convergence point), and public network address (external network IP and port returned by STUN service), that is, the first terminal sends a penetration handshake packet to the candidate address information (IP address + port) of the second terminal according to the priority order, thereby completing the establishment of the P2P connection.

[0094] In addition, in this embodiment, the priority order of each candidate address information can also be from high to low: intermediate address, local address and public network address. Connecting based on the intermediate address is more time-consuming than connecting based on the local address, but the method of connecting based on the intermediate address can be applied to more network scenarios.

[0095] Based on the above embodiment, the embodiment of the present application describes the steps before comparing the first communication path between the first terminal and the server with the second communication path between the second terminal and the server to determine whether there is a path convergence point between the first communication path and the second communication path. Specifically, the method of this embodiment includes the following steps:

[0096] Identify the network address translation type of the first communication path and the network address translation type of the second communication path; in response to the network address translation types of the first communication path and the second communication path being cone-shaped, and the first public network address of the first terminal on the server side is consistent with the second public network address of the second terminal on the server side, determine that a network address translation loop exists in the current communication network where the first terminal and the second terminal are located; after determining that a network address translation loop exists between the first terminal and the second terminal, the method also includes: comparing the first communication path with the second communication path to obtain a path convergence point.

[0097] In conjunction with the above-mentioned embodiments, the point-to-point connection method based on network address translation of the present application is mainly used to solve the problem of establishing a P2P connection when a NAT loopback exists in the current communication network (it can also be used when there is no NAT loopback). Optionally, when there is no NAT loopback in the current communication network, other existing methods can also be used to establish a P2P connection (for example, when terminal device A and terminal device B are connected to the same Wi-Fi router, and terminal devices A and B can find each other's connection through the Wi-Fi router, then one of terminal devices A or B can directly send a P2P connection request to the other party, until the other party accepts the connection request and establishes a P2P connection based on the connection response), and the details are not repeated here.

[0098] Therefore, before determining the path convergence point, it is also possible to first determine whether there is a NAT loop (network address translation loop) in the current communication network. If there is a NAT loop, it can be implemented with reference to the method provided in the aforementioned embodiment; if there is no NAT loop, it can be implemented according to other existing methods (create a P2P connection request, but the candidate address information carried in the P2P connection request does not fill in the intermediate address, and then send the connection request to the second terminal through the server; in addition, if it is determined that there is no path convergence point between the first communication path and the second communication path, a P2P connection request without filling in the intermediate address can also be created, and then the connection request is sent to the second terminal through the server). The execution process on the second terminal side is the same, and will not be repeated here. Among them, if there is a NAT loop, it is also possible to further determine whether each NAT device in the current communication network supports processing NAT loops (for example, whether the Hairpin technology is preset). If it supports processing NAT loops, other existing methods can also be used for processing. If it does not support processing NAT loops, the method of the present application can be used for processing.

[0099] Specifically, the method for determining NAT loopback includes determining whether the NAT type on the first terminal side is consistent with the type on the second terminal side and is a cone NAT, and determining whether the external network IP address of the first terminal on the server side is consistent with the external network IP address of the second terminal on the server side. If the above conditions are yes, it is determined that the first terminal and the second terminal are under the same public network NAT, that is, there is a NAT loop in the current communication network of the first terminal and the second terminal.

[0100] Among them, for example, reference can be made to Figure 3 As shown, Figure 3 This is an exemplary process sequence diagram of the point-to-point connection method based on network address translation of the present application. The first terminal can periodically initiate STUN requests to multiple platform STUN services in the server side to obtain the external network IP and port after its export NAT, and thereby identify the NAT type on this side. If multiple platform STUN services return the same external network IP and port, the NAT type on the first terminal side is cone NAT; if the external network IP and port returned by multiple platform STUN services are different, the NAT type on the first terminal side is symmetric NAT). The above method for determining the NAT type is implemented in the second terminal in the same way. The second terminal can obtain relevant network information according to the above method and report it to the server side, which will not be elaborated here.

[0101] Furthermore, the first terminal can obtain the relevant network information of the terminal (such as the second terminal) with the specified device serial number through the platform application service provided by the server. The relevant network information may include but is not limited to the LAN port IP address set of the NAT device in the communication path of the specified terminal device, the NAT type on the terminal side of the specified device, and the external network IP address of the specified terminal device. Therefore, after obtaining the relevant network information of the second terminal, the first terminal can determine whether there is a NAT loop between the first terminal and the second terminal. The first terminal can also obtain the LAN port IP addresses of each NAT device between itself and the server through methods such as traceroute commands, that is, obtain the first LAN address set.

[0102] After determining that there is a network address translation loop between the first terminal and the second terminal, the method in the above embodiment can be referred to, and the first communication path and the second communication path can be compared to obtain a path convergence point. Then, the method provided in the above embodiment can be referred to and continued to be executed, which will not be repeated here.

[0103] In summary, when the point-to-point connection method based on network address translation provided in this application is applied to the first terminal, its overall process can refer to Figure 4 As shown, Figure 4 This is an exemplary overall flow chart of the point-to-point connection method based on network address translation of the present application. Figure 4 It can be seen that in the case of NAT loops in the current communication network of this application, the NAT device at the path convergence point is identified by comparing the communication paths between terminal devices. The terminal device then performs the determination of whether there is a lower-level routing node at the convergence point, obtains the WAN port IP address of the lower-level routing node, and determines the consistency of the mapping ports of each NAT device in the transmission path, so that the terminal device can complete the ICE interaction process of both parties based on the intermediate node address information of the communication path. In the case that the public network NAT device does not support Hairpin technology, a P2P connection between terminal devices can be effectively established.

[0104] The present application also provides a point-to-point connection method based on network address translation, which is applied to a second terminal, and the second terminal communicates with the first terminal through a server. Specifically, the method includes:

[0105] In response to a connection request received from a server, the connection request is parsed to obtain the aggregation address information of the path aggregation point carried by the connection request; the address information of the lower-level routing node of the path aggregation point in the current communication network is determined according to the aggregation address information, and the second intermediate address is determined according to the address information of the lower-level routing node; in response to the second external network port of the second terminal on the server being the same as the second local port of the second terminal, a connection response is created, the connection response carries the candidate address information of the second terminal, and the candidate address information includes at least one of the second local address of the second terminal, the second intermediate address and the second public network address of the second terminal on the server; the connection response is sent to the server so that the server forwards the received connection response to the first terminal.

[0106] In conjunction with the foregoing embodiment, the method implementation process on the second terminal side can refer to the description of the implementation process on the first terminal side in the foregoing embodiment, and in conjunction with Figure 5 As shown in the flowchart, Figure 5 This is another exemplary overall flow chart of the point-to-point connection method based on network address translation of the present application.

[0107] The second terminal can regularly report its own relevant network information to the server side according to its own preset cycle. After the second terminal receives the connection request forwarded by the platform signaling service of the server side, it can determine whether the LAN port IP address of the path convergence point exists in the connection request. If not, a P2P connection response without filling in the intermediate address (filling in the local address and / or the public network address) can be created, and the P2P connection response is sent to the first terminal through the platform signaling service to start the ICE interaction process. If it exists, the intermediate address is determined according to the LAN port IP address of the path convergence point, and then a P2P connection response is created. The connection response may include filling in at least one of the local address, the public network address and the intermediate address as its candidate address information. The connection response is then sent to the first terminal via the server side to start the ICE interaction process. Among them, before the second terminal creates a connection response, it can also refer to the execution method of the first terminal to first determine the consistency between the external network port and the local port of the second terminal.

[0108] It should be further explained that the execution subject of the point-to-point connection method based on network address translation can be a point-to-point connection device based on network address translation, for example, the point-to-point connection method based on network address translation can be executed by a terminal device or a server or other processing device, wherein the terminal device can be a user equipment (UE), a computer, a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. In some possible implementations, the point-to-point connection method based on network address translation can be implemented by a processor calling a computer-readable instruction stored in a memory.

[0109] Figure 6 FIG. 1 is a block diagram of a point-to-point connection device based on network address translation, which is shown as an exemplary embodiment of the present application. The device can be applied to a first terminal. Figure 6 As shown, the exemplary point-to-point connection device 600 based on network address translation includes: a path comparison module 610, a request creation module 620, a request sending module 630 and a penetration connection module 640. Specifically:

[0110] The path comparison module 610 is used to compare the first communication path between the first terminal and the server with the second communication path between the second terminal and the server to determine whether there is a path convergence point between the first communication path and the second communication path, and the second communication path is obtained based on the server.

[0111] The request creation module 620 is used to create a connection request based on the path convergence point in response to the presence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server side is the same as the first local port of the first terminal.

[0112] The request sending module 630 is used to send a connection request to the second terminal through the server, so that the second terminal returns a connection response to the first terminal through the server based on the received connection request.

[0113] The penetration connection module 640 is used to respond to the received connection response and send the penetration connection data to the second terminal according to the connection response to establish a point-to-point connection.

[0114] In this exemplary point-to-point connection device based on network address translation, by comparing the first communication path between the first terminal and the server end with the second communication path between the second terminal and the server end, it is determined whether there is a path convergence point between the first communication path and the second communication path. In response to the existence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server end is the same as the first local port of the first terminal, it is characterized that the first terminal and the second terminal can be interactively connected based on the address information of the path convergence point of the communication paths of the two terminals, so a connection request is created based on the path convergence point. The connection request is sent to the second terminal through the server end, so that the second terminal returns a connection response to the first terminal through the server end based on the received connection request. In response to the received connection response, it can be characterized that the network penetration can be performed between the first terminal and the second terminal, and the penetration connection data is sent to the second terminal according to the connection response to perform a point-to-point connection. In this way, a point-to-point connection between different terminals can be successfully established in a scenario based on network address translation.

[0115] In addition, the present application also provides a point-to-point connection device based on network address translation, which can be applied to a second terminal, including:

[0116] The request parsing module is used to respond to the connection request sent by the server, parse the connection request, and obtain the aggregation address information of the path aggregation point carried in the connection request.

[0117] The address determination module is used to determine the address information of the lower-level routing node of the path convergence point in the current communication network according to the convergence address information, and determine the second intermediate address according to the address information of the lower-level routing node.

[0118] A response creation module is used to create a connection response in response to the second external network port of the second terminal on the server side being the same as the second local port of the second terminal, the connection response carries the candidate address information of the second terminal, the candidate address information includes at least one of the second local address of the second terminal, the second intermediate address and the second public network address of the second terminal on the server side.

[0119] The response sending module is used to send the connection response to the server side, so that the server side forwards the received connection response to the first terminal.

[0120] It should be noted that the device provided in the above embodiment and the method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment, and will not be repeated here. In practical applications, the device provided in the above embodiment can distribute the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.

[0121] The functions of each module can be found in the embodiment of the point-to-point connection method based on network address translation, which will not be described in detail here.

[0122] See also Figure 7 , Figure 7 1 is a schematic diagram of the structure of an embodiment of an electronic device of the present application. The electronic device 100 includes a memory 101 and a processor 102, and the processor 102 is used to execute program instructions stored in the memory 101 to implement the steps in any of the above-mentioned point-to-point connection method embodiments based on network address translation. In a specific implementation scenario, the electronic device 100 may include but is not limited to: a microcomputer, a server, and in addition, the electronic device 100 may also include a mobile device such as a laptop computer and a tablet computer, which is not limited here.

[0123] Specifically, the processor 102 is used to control itself and the memory 101 to implement the steps in any of the above-mentioned embodiments of the point-to-point connection method based on network address translation. The processor 102 can also be called a CPU (Central Processing Unit). The processor 102 may be an integrated circuit chip with signal processing capabilities. The processor 102 can also be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 102 can be implemented by an integrated circuit chip.

[0124] In this exemplary electronic device, by comparing the first communication path between the first terminal and the server end with the second communication path between the second terminal and the server end, it is determined whether there is a path convergence point between the first communication path and the second communication path. In response to the presence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server end is the same as the first local port of the first terminal, it is characterized that the first terminal and the second terminal can be interactively connected based on the address information of the path convergence point of the communication paths of the two terminals, so a connection request is created based on the path convergence point. The connection request is sent to the second terminal through the server end, so that the second terminal returns a connection response to the first terminal through the server end based on the received connection request. In response to the received connection response, it can be characterized that the network penetration can be performed between the first terminal and the second terminal, and the penetration connection data is sent to the second terminal according to the connection response for point-to-point connection. In this way, a point-to-point connection between different terminals can be successfully established in a scenario based on network address translation.

[0125] See also Figure 8 , Figure 8 The computer-readable storage medium 110 stores program instructions 111 that can be executed by a processor, and the program instructions 111 are used to implement the steps in any of the above-mentioned point-to-point connection method embodiments based on network address translation.

[0126] In this exemplary storage medium, by running the program instructions in the storage medium, the first communication path between the first terminal and the server end is compared with the second communication path between the second terminal and the server end, thereby determining whether there is a path convergence point between the first communication path and the second communication path. In response to the presence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server end is the same as the first local port of the first terminal, it is characterized that the first terminal and the second terminal can be interactively connected based on the address information of the path convergence point of the communication paths of the two terminals, so a connection request is created based on the path convergence point. The connection request is sent to the second terminal through the server end, so that the second terminal returns a connection response to the first terminal through the server end based on the received connection request. In response to the received connection response, it can be characterized that the first terminal and the second terminal can perform network penetration, and the penetration connection data is sent to the second terminal according to the connection response for point-to-point connection. In this way, a point-to-point connection between different terminals can be successfully established in a scenario based on network address translation.

[0127] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0128] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.

[0129] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.

[0130] In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or part of the contribution to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.

Claims

1. A point-to-point connection method based on network address translation, characterized in that: The method is applied to a first terminal, the first terminal communicates with a second terminal through a server, and the method includes: Compare a first communication path between the first terminal and the server with a second communication path between the second terminal and the server to determine whether there is a path convergence point between the first communication path and the second communication path, the second communication path being acquired based on the server; In response to a path convergence point existing between the first communication path and the second communication path, and the first external network port of the first terminal on the server side and the first local port of the first terminal being the same, creating a connection request based on the path convergence point; sending the connection request to the second terminal through the server, so that the second terminal returns a connection response to the first terminal through the server based on the received connection request; In response to the received connection response, sending the penetration connection data to the second terminal according to the connection response to establish a point-to-point connection; The step of sending, in response to the received connection response, penetration connection data to the second terminal for point-to-point connection according to the connection response includes: parsing the connection response to obtain candidate address information of the second terminal carried by the connection response; and selecting target address information from each candidate address information in turn according to the priority of each candidate address information to send the penetration connection data until the first terminal and the second terminal establish a point-to-point connection.

2. The method according to claim 1, characterized in that The comparing a first communication path between the first terminal and the server with a second communication path between the second terminal and the server to determine whether there is a path convergence point between the first communication path and the second communication path includes: Acquire a first LAN address set and a second LAN address set, wherein the first LAN address set includes LAN addresses of routing devices in the first communication path, and the second LAN address set includes LAN addresses of routing devices in the second communication path; The first LAN address set and the second LAN address set are compared, and the routing devices with the same LAN addresses are determined as the path convergence points.

3. The method according to claim 2, characterized in that The comparing the first LAN address set with the second LAN address set and determining the routing devices with the same LAN addresses as the path convergence points includes: Compare the first LAN address set with the second LAN address set to obtain a target routing device having the same LAN address among the routing devices; Determining whether the target routing device is a non-leaf node in the current communication network; If so, the target routing device is determined as the path convergence point.

4. The method according to claim 1, characterized in that In response to the presence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server side and the first local port of the first terminal being the same, before creating a connection request based on the path convergence point, the method further includes: Determine whether the first external network port obtained from the server is the same as the first local port in the local socket of the first terminal; After determining whether the first external network port obtained from the server is the same as the first local port bound to the local socket, the method further includes: In response to the first external network port and the first local port being different, a new socket is created and the current first external network port is obtained from the server for comparison, wherein the new socket includes the current first local port until the current first local port and the current first external network port are the same.

5. The method according to claim 1, characterized in that The creating a connection request based on the path convergence point includes: Determine a first local address according to the address information and port information bound to the local socket of the first terminal; Determine a first intermediate address according to address information and port information of a lower-level routing node of the path convergence point in the current communication network; Determine the first public network address according to the external network address and port information of the first terminal obtained from the server; The connection request is created, where the connection request carries candidate address information of the first terminal, where the candidate address information includes at least one of the first local address, the first intermediate address, and the first public network address.

6. The method according to claim 1, characterized in that Before comparing the first communication path between the first terminal and the server with the second communication path between the second terminal and the server to determine whether there is a path convergence point between the first communication path and the second communication path, the method further includes: identifying a network address translation type of the first communication path and a network address translation type of the second communication path; In response to the network address translation type of the first communication path and the second communication path being cone-type, and the first public network address of the first terminal on the server side and the second public network address of the second terminal on the server side being consistent, it is determined that a network address translation loop exists in the current communication network where the first terminal and the second terminal are located; After determining that a network address translation loop exists between the first terminal and the second terminal, the method further includes: The first communication path is compared with the second communication path to obtain the path convergence point.

7. A point-to-point connection method based on network address translation, characterized in that: The method is applied to a second terminal, the second terminal communicates with the first terminal through a server, and the method includes: In response to the connection request received from the server, the connection request is parsed to obtain the convergence address information of the path convergence point carried by the connection request; The connection request is created by the first terminal and sent to the second terminal through the server; the step of the first terminal creating the connection request includes: comparing a first communication path between the first terminal and the server with a second communication path between the second terminal and the server, determining whether there is a path convergence point between the first communication path and the second communication path, the second communication path being acquired based on the server; in response to the existence of a path convergence point between the first communication path and the second communication path, and the first external network port of the first terminal on the server being the same as the first local port of the first terminal, creating the connection request based on the path convergence point; Determine the address information of the lower-level routing node of the path convergence point in the current communication network according to the convergence address information, and determine the second intermediate address according to the address information of the lower-level routing node; In response to the second external network port of the second terminal on the server being the same as the second local port of the second terminal, creating a connection response, the connection response carrying candidate address information of the second terminal, the candidate address information including at least one of the second local address of the second terminal, the second intermediate address, and the second public network address of the second terminal on the server; The connection response is sent to the server end, so that the server end forwards the received connection response to the first terminal, so that the first terminal parses the connection response and obtains the candidate address information of the second terminal carried by the connection response; according to the priority of each candidate address information, the target address information is selected from each candidate address information in turn to send the penetration connection data until the first terminal and the second terminal establish a point-to-point connection.

8. An electronic device, characterized in that: The invention comprises a memory and a processor, wherein the processor is used to execute program instructions stored in the memory to implement the method according to any one of claims 1 to 7.

9. A computer-readable storage medium having program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Point to point data transmission method and device

    CN105721570A

  • NAT traversing method

    CN110113439A