CN111800341B - Cross-router terminal communication method and device - Google Patents

Cross-router terminal communication method and device Download PDF

Info

Publication number
CN111800341B
CN111800341B CN202010631406.5A CN202010631406A CN111800341B CN 111800341 B CN111800341 B CN 111800341B CN 202010631406 A CN202010631406 A CN 202010631406A CN 111800341 B CN111800341 B CN 111800341B
Authority
CN
China
Prior art keywords
nat
protocol
router
public network
external public
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010631406.5A
Other languages
Chinese (zh)
Other versions
CN111800341A (en
Inventor
陈天宇
梁波
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhuhai Kingsoft Digital Network Technology Co Ltd
Original Assignee
Zhuhai Kingsoft Online Game Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhuhai Kingsoft Online Game Technology Co Ltd filed Critical Zhuhai Kingsoft Online Game Technology Co Ltd
Priority to CN202010631406.5A priority Critical patent/CN111800341B/en
Publication of CN111800341A publication Critical patent/CN111800341A/en
Application granted granted Critical
Publication of CN111800341B publication Critical patent/CN111800341B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/256NAT traversal

Abstract

The application provides a cross-router terminal communication method, which is applied to a user communication node in an internal local area network, and comprises the following steps: detecting the network environment of an internal local area network, and judging whether an NAT router in the internal local area network supports a UPnP protocol and an NAT-pmp protocol or not; if yes, adding port mapping on the NAT router through the UPnP protocol and the NAT-pmp protocol, and communicating with other communication nodes in the external public network through the port mapping so as to realize NAT penetration; if not, the communication is carried out with other communication nodes in the external public network under the ICE protocol framework through the STUN protocol and the TURN protocol, thereby realizing NAT penetration.

Description

Cross-router terminal communication method and device
Technical Field
The present application relates to the field of internet technologies, and in particular, to a method and an apparatus for cross-router terminal communication, a computing device, and a computer-readable storage medium.
Background
In the prior art, when communication between two terminals connected to different routers is implemented, NAT traversal technology is used: i.e., network address translation techniques. Because the IPV4 has scarce resources, multiple devices in the home share one IP address, and in order to protect the devices in the home lan from external attacks, the router dynamically allocates the IP address of the home lan to the devices, so that external devices that are not connected to the home lan cannot be connected even if they acquire the IP address of the terminal, and thus devices outside the home lan cannot be directly connected to devices inside the home lan.
In the prior art, when solving the problem, a central server across the local area network is provided, and the central server is used for network address conversion of cross-router communication and can confirm the IP address and the port number of each device of the terminal in the local area network inside the terminal.
Disclosure of Invention
In view of this, embodiments of the present application provide a cross-router terminal communication method and apparatus, a computing device, and a computer-readable storage medium, so as to solve technical defects in the prior art.
According to a first aspect of embodiments herein, there is provided a cross-router terminal communication method, including:
detecting the network environment of an internal local area network, and judging whether an NAT router in the internal local area network supports a UPnP protocol and an NAT-pmp protocol or not;
if yes, adding port mapping on the NAT router through the UPnP protocol and the NAT-pmp protocol, and communicating with other communication nodes in the external public network through the port mapping so as to realize NAT penetration;
if not, the communication is carried out with other communication nodes in the external public network under the ICE protocol framework through the STUN protocol and the TURN protocol, thereby realizing NAT penetration.
According to a second aspect of embodiments herein, there is provided a cross-router terminal communication device comprising:
the network detection module is configured to detect a network environment of an internal local area network and judge whether an NAT router in the internal local area network supports a UPnP protocol and an NAT-pmp protocol or not; if yes, executing a first penetration module; if not, executing a second penetration module;
the first penetration module is configured to add port mapping on the NAT router through a UPnP protocol and a NAT-pmp protocol, and communicate with other communication nodes in an external public network through the port mapping so as to realize NAT penetration;
and the second penetration module is configured to communicate with other communication nodes in the external public network under the ICE protocol framework through the STUN protocol and the TURN protocol so as to realize NAT penetration.
According to a third aspect of embodiments herein, there is provided a computing device comprising a memory, a processor and computer instructions stored on the memory and executable on the processor, the processor implementing the steps of the cross-router terminal communication method when executing the instructions.
According to a fourth aspect of embodiments herein, there is provided a computer readable storage medium storing computer instructions which, when executed by a processor, implement the steps of the cross-router terminal communication method.
The method adopts a progressive NAT penetration scheme, firstly establishes P2P connection by using a port mapping exposure function of UPnP service and NAT-pmp service, and secondly realizes the NAT penetration scheme by using an ICE protocol frame, so that the communication connection of the terminal can be realized by using a simple method as far as possible under the condition of ensuring that the NAT of a communication node is penetrated, and compared with the prior art, a large amount of resources, manpower and material resources are saved.
Drawings
FIG. 1 is a block diagram of a computing device provided by an embodiment of the present application;
fig. 2 is a flowchart of a cross-router terminal communication method provided in an embodiment of the present application;
fig. 3 is another flowchart of a cross-router terminal communication method provided in an embodiment of the present application;
fig. 4 is another flowchart of a cross-router terminal communication method provided in an embodiment of the present application;
fig. 5 is another flowchart of a cross-router terminal communication method provided in an embodiment of the present application;
fig. 6 is another flowchart of a cross-router terminal communication method provided in an embodiment of the present application;
fig. 7 is a system architecture diagram of a cross-router terminal communication method according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of a cross-router terminal communication device according to an embodiment of the present application.
Detailed Description
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present application. This application is capable of implementation in many different ways than those herein set forth and of similar import by those skilled in the art without departing from the spirit and scope of this application, and thus this application is not limited to the specific implementations disclosed below.
The terminology used in the description of the one or more embodiments is for the purpose of describing the particular embodiments only and is not intended to be limiting of the description of the one or more embodiments. As used in this specification and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used in one or more embodiments of the present specification refers to and encompasses any and all possible combinations of one or more of the associated listed items.
It should be understood that although the terms first, second, etc. may be used herein in one or more embodiments to describe various information, these information should not be limited by these terms. These terms are only used to distinguish one type of information from another. For example, a first can also be referred to as a second and, similarly, a second can also be referred to as a first without departing from the scope of one or more embodiments of the present description. The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination", depending on the context.
First, the noun terms to which one or more embodiments of the present invention relate are explained.
NAT: NAT (Network Address Translation), also called Network masking or IP masking, is a Network Address Translation technology, and mainly converts an internal private IP Address (private IP) into a public IP Address (public IP) that can be used in a public Network.
NAT router: a wireless router with NAT service.
UPnP protocol: the UPnP (Universal Plug and Play) protocol is a structure in which various smart devices, wireless devices, and personal computers etc. implement peer-to-peer network connections (P2P) throughout the world, and NAT traversal technology allows network applications to detect whether they are behind a UPnP-capable NAT device. These programs will then obtain a shared globally routable IP address and configure the port mapping to forward packets from the NAT's external port onto the internal port used by the application without the user having to manually map the port or otherwise do so. NAT traversal technology allows network devices or peer-to-peer applications to communicate with the outside world across a NAT gateway by dynamically opening and closing communication ports with external services.
NAT-pmp protocol: devices within the private network are allowed to communicate with the router so that external devices can communicate across the router, which can be understood as another way of common UPnP.
Port mapping: the port mapping is to map one port of the IP address of the external network host to one machine in the internal network to provide corresponding service, and when the user accesses the port of the IP in the network, the server automatically maps the request to the machine in the corresponding local area network.
STUN protocol: the STUN protocol is renamed in RFC5389 as Session traffic Utilities for NAT, i.e. NAT Session penetration utility. Here, NAT session traversal utility is located as a protocol for other protocols that address NAT traversal issues. It can be used for the terminal device to check the IP address and port number assigned to the terminal by the NAT. At the same time, it is also used to check the connectivity between two terminals, rather than a keep-alive protocol that maintains NAT binding entries. STUN can be used for multiple NAT types and is not required to provide special behavior. STUN itself is no longer a complete NAT traversal solution, and it acts as a tool in a NAT traversal solution. This is the most important change compared to the RFC3489/STUN version.
TURN protocol: TURN, defined in RFC5766, is known as the Transversal Using Relay around NAT (TURN): relay Extensions to Session Traffics Utilities for NAT (STUN), i.e. Traversal of NAT using relays: relay extension of STUN. In brief, TURN and STUN have in common that NAT traversal is achieved by modifying the private network address in the application layer, and heterology is that TURN performs traversal in a "man-in-the-middle" manner of two-party communication. If one host is behind the NAT, it cannot in some cases be connected directly point-to-point with other hosts. In these cases, it needs to use the relay connection service provided by the intermediate mesh point. The TURN protocol is used to allow a host to control the operation of a relay and exchange data with a peer using the relay. TURN differs from other relay control protocols in that it can allow one client to connect with multiple peers using one relay address. The TURN protocol is designed as part of the ICE for NAT traversal, although it can be used alone without ICE.
ICE protocol: the protocol for NAT traversal for UDP based request/answer mode multimedia sessions, the ICE protocol, which may be utilized by any request/question mode protocol, utilizes the STUN protocol and its extended version TURN.
C/S architecture: Server-Client, i.e., Client-Server (C/S) architecture. The C/S structure generally takes a two-layer structure. The server is responsible for managing data, and the client is responsible for completing interaction tasks with the user. The client is connected with the server through the local area network, receives the request of the user, and makes the request to the server through the network to operate the database. The server receives the request of the client, submits the data to the client, and the client calculates the data and presents the result to the user.
In the present application, a cross-router terminal communication method and apparatus, a computing device, and a computer-readable storage medium are provided, which are described in detail in the following embodiments one by one.
FIG. 1 shows a block diagram of a computing device 100, according to an embodiment of the present description. The components of the computing device 100 include, but are not limited to, memory 110 and processor 120. The processor 120 is coupled to the memory 110 via a bus 130 and a database 150 is used to store data.
Computing device 100 also includes access device 140, access device 140 enabling computing device 100 to communicate via one or more networks 160. Examples of such networks include the Public Switched Telephone Network (PSTN), a Local Area Network (LAN), a Wide Area Network (WAN), a Personal Area Network (PAN), or a combination of communication networks such as the internet. Access device 140 may include one or more of any type of network interface (e.g., a Network Interface Card (NIC)) whether wired or wireless, such as an IEEE802.11 Wireless Local Area Network (WLAN) wireless interface, a worldwide interoperability for microwave access (Wi-MAX) interface, an ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a bluetooth interface, a Near Field Communication (NFC) interface, and so forth.
In one embodiment of the present description, the above-described components of computing device 100 and other components not shown in FIG. 1 may also be connected to each other, such as by a bus. It should be understood that the block diagram of the computing device architecture shown in FIG. 1 is for purposes of example only and is not limiting as to the scope of the description. Other components may be added or replaced as desired by those skilled in the art.
Computing device 100 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., tablet, personal digital assistant, laptop, notebook, netbook, etc.), a mobile phone (e.g., smartphone), a wearable computing device (e.g., smartwatch, smartglasses, etc.), or other type of mobile device, or a stationary computing device such as a desktop computer or PC. Computing device 100 may also be a mobile or stationary server.
Wherein the processor 120 may perform the steps of the method shown in fig. 2. Fig. 2 is a schematic flow chart diagram illustrating a cross-router terminal communication method according to an embodiment of the present application, applied to a user communication node in an internal local area network, including steps 202 to 206.
Step 202: and detecting the network environment of the internal local area network, and judging whether the current NAT router in the internal local area network supports the UPnP protocol and the NAT-pmp protocol. If yes, go to step 204; if not, go to step 206.
At present, due to the use of a large number of NAT devices, P2P connection cannot be established between user communication nodes located in different network environments. Firstly, the method and the device judge whether the current NAT router in the internal local area network supports the UPnP protocol and the NAT-pmp protocol or not by detecting the network environment of the internal local area network connected with the user communication node.
Step 204: and adding port mapping on the NAT router through the UPnP protocol and the NAT-pmp protocol, and communicating with other communication nodes in the external public network through the port mapping so as to realize NAT penetration.
In an embodiment of the present application, when the NAT router in the current internal local area network supports the UPnP protocol and the NAT-pmp protocol, a port mapping is directly added to the NAT router through the UPnP protocol and the NAT-pmp protocol, so as to communicate with other communication nodes in the external public network through the port mapping, which specifically includes:
And starting UPnP service and NAT-pmp service, sending a request for adding port mapping to the NAT router, exposing the port mapping corresponding to the IP address and the port number of the user communication node in the internal local area network in the external public network by the NAT router, and realizing data communication with the user communication node by other communication nodes in the external public network through the port mapping.
Step 206: and through the STUN protocol and the TURN protocol, the communication is carried out with other communication nodes in the external public network under the ICE protocol framework, so that NAT penetration is realized.
In the embodiment of the present application, under the condition that the NAT router in the current internal local area network does not support the UPnP protocol and the NAT-pmp protocol, the present application adopts an ICE protocol framework, detects the NAT type of the NAT router through the STUN protocol, and performs traversal on most NAT routers through the STUN protocol and the TURN protocol in the ICE protocol framework, and meanwhile, it should be noted that, for the symmetric NAT, because the mapping relationship between the IP address and the port number of the communication node is changed, the symmetric NAT cannot perform direct traversal through the ICE protocol framework to establish a P2P connection, so that the present application performs assisted communication through a preset NAT port guessing algorithm and a relay server under the ICE protocol framework to form a C/S framework to achieve traversal.
The NAT penetration scheme is suitable for various mainstream electronic equipment and operating systems, and can meet the development trend of modern science and technology and meet various requirements of users.
Specifically, as shown in fig. 3, the communication with other communication nodes in the external public network is performed under the ICE protocol framework through the STUN protocol and the TURN protocol, including steps 302 to 306.
Step 302: and determining the NAT type of the NAT router through the STUN protocol.
In the above embodiment, determining the NAT type of the NAT router through the STUN protocol includes:
and erecting a STUN server in an external public network, testing the NAT router through the STUN server under an ICE protocol frame, and determining that the NAT type of the NAT router is a complete cone type NAT, a limited cone type NAT, a port limited type NAT or a symmetrical type NAT.
Specifically, the STUN server receives a request of a user communication node, encapsulates an IP address and a port number corresponding to the user communication node into an icedirectory, determines an NAT type of the NAT router through a preset logic judgment mechanism, sends the NAT type of the NAT router back to the user communication node, and judges whether the TURN server needs to coordinate to perform the next work according to the NAT type.
Step 304: and under the condition that the NAT type of the NAT router is a complete cone type NAT, directly communicating with other communication nodes in an external public network through the NAT router.
In the above case, the STUN server does not need to perform other operations, and the user communication node can directly communicate with other clients through the NAT router.
Step 306: and under the condition that the NAT type of the NAT router is other NAT types, based on the ICE protocol framework, the communication is carried out with other communication nodes in the external public network through the TURN protocol under the coordination of the STUN protocol.
In the above embodiment, as shown in fig. 4, the step 306 specifically includes steps 402 to 404.
Step 402: and under the condition that the NAT type of the NAT router is a limited conical NAT and a port limited NAT, based on an ICE protocol frame, communicating with other communication nodes in an external public network by using a TURN protocol and adopting an NAT holing mode under the coordination of an STUN protocol.
Specifically, as shown in fig. 5, the step 402 specifically includes steps 502 to 504.
Step 502: and erecting a TURN server in the external public network, and acquiring the IP address and the port number of the user communication node in the internal local area network and the IP addresses and the port numbers of other communication nodes in the external public network by the TURN server under the coordination of the STUN server.
Step 504: and under the action of the TURN server, sending the IP address and the port number of the user communication node to other communication nodes in the external public network, and receiving the IP addresses and the port numbers of the other communication nodes, so that the communication between the user communication node and the other communication nodes is realized.
Under the condition that the NAT type of the NAT router is the limited cone type NAT and the port limited type NAT, the STUN server can coordinate the TURN server to carry out NAT holing, namely the TURN server can command the user communication node and other communication nodes to send a piece of information mutually, so that the respective NAT router leaves the hole of the other party, and the user communication node and the other communication nodes can be communicated.
Step 404: and under the condition that the NAT type of the NAT router is a symmetric NAT, constructing and forming a C/S framework, and realizing communication with other communication nodes in the external public network by using a TURN protocol and a preset NAT port guessing algorithm.
Specifically, as shown in fig. 6, the step 404 specifically includes steps 602 to 608.
Step 602: and acquiring random port numbers distributed to at least two ports of the user communication node by the NAT router.
For example, the user communications node has an IP address of 192.168.0.100 and is accessed externally by a first process through a NAT router, the NAT router may assign a port mapping of 10.11.161.110/50000 to the user communications node, and the user communications node is accessed externally again by a second process, and the router may reassign a new port 10.11.161.110/50002 to the user communications node.
Step 604: guessing the relation of the random port numbers of the at least two ports, and acquiring the port number range set of the user communication node and other communication nodes.
According to the source code of Linux, the symmetric NAT mostly adopts incremental port allocation, that is, a fixed value is added each time, if the port is occupied, the port is added once, that is, the ICE server notifies the user of a possible port number range set of the communication node and other communication nodes, and the NAT port guessing algorithm performs traversal attempt on each port in the possible port number range set, so as to implement NAT traversal.
Step 606: and performing traversal attempt on the port corresponding to each port number in the port number range set to acquire the IP address and the port number of the user communication node in the internal local area network.
The core principle of the NAT port guessing technology used in the present application is: the NAT router distributes the IP address and the port number, wherein the IP address is fixed and the port number is random, the random has a certain probability of being pseudo-random, namely, the original port number is added with a fixed integer to obtain a new port number, for the pseudo-random mode, the port guessing can be directly cracked to obtain the IP address and the port number of the user communication node in the internal local area network, and the connection can be realized.
Step 608: the method comprises the steps that a TURN server is erected in an external public network, the user communication node communicates with the TURN server through a corresponding IP address and a corresponding port number, and the TURN server forwards data information sent from the user communication node to other communication nodes connected with the TURN server in the external public network.
The method adopts a progressive NAT penetration scheme, firstly establishes P2P connection by using a port mapping exposure function of UPnP service and NAT-pmp service, and secondly realizes the NAT penetration scheme by using an ICE protocol frame, so that the communication connection of the terminal can be realized by using a simple method as far as possible under the condition of ensuring that the NAT of a communication node is penetrated, and compared with the prior art, a large amount of resources, manpower and material resources are saved.
Fig. 7 shows a system architecture of cross-router-terminal communication according to an embodiment of the present specification, where the cross-router-terminal communication method is described by taking a user communication node a in an internal local area network and another communication node B in an external public network as an example, and includes steps 702 to 716.
Step 702: the user communication node A detects the network environment of the internal local area network and judges whether the NAT router in the internal local area network supports the UPnP protocol and the NAT-pmp protocol or not.
Step 704: and if so, adding port mapping on the NAT router through the UPnP protocol and the NAT-pmp protocol, and communicating the user communication node A with other communication nodes B in the external public network through the port mapping.
Step 706: and if not, determining the NAT type of the NAT router through the STUN protocol.
Step 708: and under the condition that the NAT type of the NAT router is a complete cone type NAT, directly communicating with other communication nodes in an external public network through the NAT router.
Step 710: under the condition that the NAT type of the NAT router is a restricted cone type NAT and a port restricted type NAT, a TURN server is erected in an external public network, and under the coordination of the TURN server, the TURN server acquires the IP address and the port number of the user communication node A in an internal local area network and the IP addresses and the port numbers of other communication nodes B in the external public network;
step 712: and sending the IP address and the port number of the user communication node A to other communication nodes B, and sending the IP address and the port number of the other communication nodes B to the user communication node A, thereby realizing the communication between the user communication node A and the other communication nodes B.
Step 714: and under the condition that the NAT type of the NAT router is a symmetric NAT, acquiring the IP address and the port number of the user communication node A in the internal local area network through a preset NAT port guessing algorithm.
Step 716: and the user communication node A communicates with other communication nodes B through the corresponding IP address and port number in the internal local area network.
Optionally, the other communication node B may be a game server.
The NAT traversal method can enable the user communication node A on the player side to directly realize communication connection with other communication nodes B across the router, so that the resource packet is updated or the user communication node A directly enters a game and other operations, and the game experience of the player is greatly improved.
Corresponding to the above method embodiment, the present specification further provides an embodiment of a cross-router terminal communication device, and fig. 8 shows a schematic structural diagram of the cross-router terminal communication device according to an embodiment of the present specification.
As shown in fig. 8, the apparatus includes:
a network detection module 801 configured to detect a network environment of an internal local area network, and determine whether an NAT router in the internal local area network supports a UPnP protocol and an NAT-pmp protocol; if yes, executing a first penetrating module; if not, executing a second penetration module;
the first traversal module 802 is configured to add a port mapping on the NAT router through the UPnP protocol and the NAT-pmp protocol, and communicate with other communication nodes in the external public network through the port mapping, so as to implement NAT traversal;
And a second penetration module 803 configured to communicate with other communication nodes in the external public network under the ICE protocol framework through the STUN protocol and the TURN protocol, so as to implement NAT penetration.
Optionally, the network detecting module 801 includes:
and the port mapping exposure unit is configured to start UPnP service and NAT-pmp service, send a request for adding port mapping to the NAT router, expose the port mapping corresponding to the IP address and the port number in the internal local area network of the user communication node in the external public network by the NAT router, and realize data communication with the user communication node through the port mapping by other communication nodes in the external public network.
Optionally, the first penetrating module 802 includes:
a type judging unit configured to determine the NAT type of the NAT router by a STUN protocol;
the first penetration subunit is configured to directly communicate with other communication nodes in an external public network through the NAT router under the condition that the NAT type of the NAT router is a full cone type NAT;
and the first penetration subunit is also configured to communicate with other communication nodes in the external public network through the TURN protocol and under the coordination of the STUN protocol based on the ICE protocol framework under the condition that the NAT type of the NAT router is other NAT type.
Optionally, the type determining unit includes:
and the STUN testing subunit is configured to erect a STUN server in an external public network, test the NAT router through the STUN server under an ICE protocol frame, and determine that the NAT type of the NAT router is a full cone type NAT, a limited cone type NAT, a port limited type NAT or a symmetric type NAT.
Optionally, the first penetrating subunit includes:
the first communication subunit is configured to communicate with other communication nodes in the external public network in a mode of NAT holing under coordination of a TURN protocol and a STUN protocol through a TURN protocol based on an ICE protocol framework under the condition that the NAT type of the NAT router is a restricted cone type NAT and a port restricted type NAT;
and the second communication subunit is configured to construct and form a C/S architecture under the condition that the NAT type of the NAT router is a symmetric NAT, and realize communication with other communication nodes in the external public network by using a TURN protocol and a preset NAT port guessing algorithm.
Optionally, the first communication subunit is further configured to:
the TURN server is erected in an external public network, and under the coordination of the TURN server, the TURN server acquires the IP address and the port number of the user communication node in an internal local area network and the IP addresses and the port numbers of other communication nodes in the external public network;
And under the action of the TURN server, sending the IP address and the port number of the user communication node to other communication nodes in the external public network, and receiving the IP addresses and the port numbers of the other communication nodes, so that the communication between the user communication node and the other communication nodes is realized.
Optionally, the first communication subunit is further configured to:
acquiring random port numbers of at least two ports allocated to the user communication node by the NAT router;
guessing the relation of the random port numbers of the at least two ports to obtain port number range sets of the user communication node and other communication nodes;
performing traversal attempt on a port corresponding to each port number in the port number range set to acquire an IP address and a port number of the user communication node in an internal local area network;
a TURN server is installed in the external public network, the user communication node communicates with the TURN server through a corresponding IP address and port number, and the TURN server transfers data information transmitted from the user communication node to another communication node connected to the TURN server in the external public network.
The method adopts a progressive NAT penetration scheme, firstly establishes P2P connection by using a port mapping exposure function of UPnP service and NAT-pmp service, and secondly realizes the NAT penetration scheme by using an ICE protocol frame, so that the communication connection of the terminal can be realized by using a simple method as far as possible under the condition of ensuring that the NAT of a communication node is penetrated, and compared with the prior art, a large amount of resources, manpower and material resources are saved.
An embodiment of the present application further provides a computing device, including a memory, a processor, and computer instructions stored on the memory and executable on the processor, where the processor implements the following steps when executing the instructions:
detecting the network environment of an internal local area network, and judging whether an NAT router in the internal local area network supports a UPnP protocol and an NAT-pmp protocol or not;
if yes, adding port mapping on the NAT router through the UPnP protocol and the NAT-pmp protocol, and communicating with other communication nodes in the external public network through the port mapping so as to realize NAT penetration;
if not, the communication is carried out with other communication nodes in the external public network under the ICE protocol framework through the STUN protocol and the TURN protocol, thereby realizing NAT penetration.
An embodiment of the present application also provides a computer readable storage medium storing computer instructions, which when executed by a processor, implement the steps of the cross-router terminal communication method as described above.
The above is an illustrative scheme of a computer-readable storage medium of the embodiment. It should be noted that the technical solution of the computer-readable storage medium and the technical solution of the above-mentioned cross-router terminal communication method belong to the same concept, and details that are not described in detail in the technical solution of the computer-readable storage medium can be referred to the description of the technical solution of the above-mentioned cross-router terminal communication method.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The computer instructions comprise computer program code which may be in the form of source code, object code, an executable file or some intermediate form, or the like. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
It should be noted that, for the sake of simplicity, the above-mentioned method embodiments are described as a series of acts or combinations, but those skilled in the art should understand that the present application is not limited by the described order of acts, as some steps may be performed in other orders or simultaneously according to the present application. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required in this application.
In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to the related descriptions of other embodiments.
The preferred embodiments of the present application disclosed above are intended only to aid in the explanation of the application. Alternative embodiments are not exhaustive and do not limit the invention to the precise embodiments described. Obviously, many modifications and variations are possible in light of the above teaching. The embodiments were chosen and described in order to best explain the principles of the application and the practical application, to thereby enable others skilled in the art to best understand and utilize the application. The application is limited only by the claims and their full scope and equivalents.

Claims (9)

1. A cross-router terminal communication method is applied to a user communication node in an internal local area network, and comprises the following steps:
detecting the network environment of an internal local area network, and judging whether an NAT router in the internal local area network supports a UPnP protocol and an NAT-pmp protocol or not;
if yes, adding port mapping on the NAT router through the UPnP protocol and the NAT-pmp protocol, and communicating with other communication nodes in the external public network through the port mapping so as to realize NAT penetration;
if not, communicating with other communication nodes in the external public network under an ICE protocol frame through a STUN protocol and a TURN protocol, thereby realizing NAT penetration;
the method is characterized in that through a STUN protocol and a TURN protocol, communication is carried out with other communication nodes in an external public network under an ICE protocol framework, and the method comprises the following steps:
determining the NAT type of the NAT router through a STUN protocol;
under the condition that the NAT type of the NAT router is a complete cone type NAT, the NAT router directly communicates with other communication nodes in an external public network;
and under the condition that the NAT type of the NAT router is other NAT types, based on the ICE protocol framework, the communication is carried out with other communication nodes in the external public network through the TURN protocol under the coordination of the STUN protocol.
2. The method of claim 1, wherein adding a port mapping on the NAT router through the UPnP protocol and the NAT-pmp protocol, and communicating with other communication nodes in the external public network through the port mapping comprises:
and starting UPnP service and NAT-pmp service, sending a request for adding port mapping to the NAT router, exposing the port mapping corresponding to the IP address and the port number of the user communication node in the internal local area network in the external public network by the NAT router, and realizing data communication with the user communication node by other communication nodes in the external public network through the port mapping.
3. The method of claim 1, wherein determining the NAT type of the NAT router via the STUN protocol comprises:
and erecting a STUN server in an external public network, testing the NAT router through the STUN server under an ICE protocol frame, and determining that the NAT type of the NAT router is a full cone type NAT, a limited cone type NAT, a port limited type NAT or a symmetrical type NAT.
4. The method of claim 3, wherein in the case that the NAT type of the NAT router is other NAT type, communicating with other communication nodes in the external public network through TURN protocol and under coordination of ST UN protocol based on ICE protocol framework, comprises:
Under the condition that the NAT type of the NAT router is a limited conical NAT and a port limited NAT, based on an ICE protocol frame, the TURN protocol is used for communicating with other communication nodes in an external public network in a NAT holing mode under the coordination of the STUN protocol;
and under the condition that the NAT type of the NAT router is a symmetric NAT, constructing and forming a C/S framework, and realizing communication with other communication nodes in the external public network by using a TURN protocol and a preset NAT port guessing algorithm.
5. The method according to claim 4, wherein based on the ICE protocol framework, communicating with other communication nodes in the external public network by using NAT holing under coordination of TURN protocol and STUN protocol comprises:
the TURN server is erected in an external public network, and under the coordination of the TURN server, the TURN server acquires the IP address and the port number of the user communication node in an internal local area network and the IP addresses and the port numbers of other communication nodes in the external public network;
and under the action of the TURN server, sending the IP address and the port number of the user communication node to other communication nodes in the external public network, and receiving the IP addresses and the port numbers of the other communication nodes, so that the communication between the user communication node and the other communication nodes is realized.
6. The method of claim 4, wherein the communication with other communication nodes in the external public network is achieved through the TURN protocol and by using a preset NAT port guessing algorithm, and the method comprises the following steps:
acquiring random port numbers of at least two ports allocated to the user communication node by the NAT router;
guessing the relation of the random port numbers of the at least two ports to obtain a port number range set of the user communication node and other communication nodes;
performing traversal attempt on a port corresponding to each port number in the port number range set to acquire an IP address and a port number of the user communication node in an internal local area network;
the method comprises the steps that a TURN server is erected in an external public network, the user communication node communicates with the TURN server through a corresponding IP address and a corresponding port number, and the TURN server forwards data information sent from the user communication node to other communication nodes connected with the TURN server in the external public network.
7. A cross-router terminal communication apparatus, provided at a user communication node in an internal local area network, comprising:
the network detection module is configured to detect a network environment of an internal local area network and judge whether an NAT router in the internal local area network supports a UPnP protocol and an NAT-pmp protocol or not; if yes, executing a first penetrating module; if not, executing a second penetration module;
The first penetration module is configured to add port mapping on the NAT router through a UPnP protocol and a NAT-pmp protocol, and communicate with other communication nodes in an external public network through the port mapping so as to realize NAT penetration;
the second penetration module is configured to communicate with other communication nodes in the external public network under the ICE protocol framework through the STUN protocol and the TURN protocol so as to realize NAT penetration;
wherein the second penetration module comprises:
a type judging unit configured to determine the NAT type of the NAT router through a STUN protocol;
the first penetration subunit is configured to directly communicate with other communication nodes in an external public network through the NAT router under the condition that the NAT type of the NAT router is a complete cone-shaped NA T;
and the first penetration subunit is also configured to communicate with other communication nodes in the external public network through the TURN protocol and under the coordination of the STUN protocol based on the ICE protocol framework under the condition that the NAT type of the NAT router is other NAT type.
8. A computing device comprising a memory, a processor, and computer instructions stored on the memory and executable on the processor, wherein the processor implements the steps of the method of any one of claims 1-6 when executing the instructions.
9. A computer-readable storage medium storing computer instructions, which when executed by a processor, perform the steps of the method of any one of claims 1 to 6.
CN202010631406.5A 2020-07-03 2020-07-03 Cross-router terminal communication method and device Active CN111800341B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010631406.5A CN111800341B (en) 2020-07-03 2020-07-03 Cross-router terminal communication method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010631406.5A CN111800341B (en) 2020-07-03 2020-07-03 Cross-router terminal communication method and device

Publications (2)

Publication Number Publication Date
CN111800341A CN111800341A (en) 2020-10-20
CN111800341B true CN111800341B (en) 2022-05-31

Family

ID=72810115

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010631406.5A Active CN111800341B (en) 2020-07-03 2020-07-03 Cross-router terminal communication method and device

Country Status (1)

Country Link
CN (1) CN111800341B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114928616A (en) * 2021-02-03 2022-08-19 上海哔哩哔哩科技有限公司 Transmission method and system of peer-to-peer network
CN113179315B (en) * 2021-04-26 2022-11-29 缀初网络技术(上海)有限公司 Method, system and readable storage medium for providing communication between devices in multiple local area networks

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102340520A (en) * 2010-07-20 2012-02-01 上海未来宽带技术及应用工程研究中心有限公司 Private network detection and traverse compounding method for P2P (Peer-to-Peer) network application system
CN102685268A (en) * 2012-05-22 2012-09-19 北京邮电大学 Fast private network traversal method based on ICE (Information and Content Exchange) protocol in VoIP (Voice over Internet Protocol)
CN105141711A (en) * 2015-08-24 2015-12-09 北京息通网络技术有限公司 Symmetrical NAT traversal method and system based on big data analysis
CN105827748A (en) * 2016-05-12 2016-08-03 东莞市南星电子有限公司 Method for traversing Symmetric NAT (Network Address Translator) device by SIP (Session Initiation Protocol) based on ICE (Interactive Connectivity Establishment)

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8224985B2 (en) * 2005-10-04 2012-07-17 Sony Computer Entertainment Inc. Peer-to-peer communication traversing symmetric network address translators
CN104506666A (en) * 2014-12-18 2015-04-08 北京邮电大学 Proxy method and system for crossing of massive TCP (Transmission Control Protocol) through symmetrical NAT (Network Address Translation)
CN105979022B (en) * 2016-04-28 2020-10-02 深圳市Tcl高新技术开发有限公司 NAT (network Address translation) penetrating method and system based on UPnP (Universal plug and Play) protocol
US10601773B2 (en) * 2017-10-18 2020-03-24 Nexmo, Inc. Method and a system for using relays for network optimization in IP-based communication networks

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102340520A (en) * 2010-07-20 2012-02-01 上海未来宽带技术及应用工程研究中心有限公司 Private network detection and traverse compounding method for P2P (Peer-to-Peer) network application system
CN102685268A (en) * 2012-05-22 2012-09-19 北京邮电大学 Fast private network traversal method based on ICE (Information and Content Exchange) protocol in VoIP (Voice over Internet Protocol)
CN105141711A (en) * 2015-08-24 2015-12-09 北京息通网络技术有限公司 Symmetrical NAT traversal method and system based on big data analysis
CN105827748A (en) * 2016-05-12 2016-08-03 东莞市南星电子有限公司 Method for traversing Symmetric NAT (Network Address Translator) device by SIP (Session Initiation Protocol) based on ICE (Interactive Connectivity Establishment)

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
GB/T28181协议NAT穿越方案研究;孟卿卿等;《信息技术》;20200325(第03期);全文 *
NAT穿越技术研究;陈恒勋等;《现代信息科技》;20200325(第06期);全文 *
基于扩展ICE框架的NAT穿越技术研究;卓志鹏;《中国优秀博硕士学位论文全文数据库(硕士)信息科技辑》;20160315;正文第23页 *

Also Published As

Publication number Publication date
CN111800341A (en) 2020-10-20

Similar Documents

Publication Publication Date Title
EP2645679B1 (en) Method and apparatus for message transmission
EP2112788B1 (en) A method and node for p2p content sharing
US9143421B2 (en) Network system capable of implementing stun with the assistance of two network devices and method thereof
US8725883B2 (en) Method for the establishing of peer-to-peer multimedia sessions in a communication system
CN112637364B (en) Method, client and system for establishing P2P connection
US20130308628A1 (en) Nat traversal for voip
CN111800341B (en) Cross-router terminal communication method and device
CN101895590A (en) UDT-based system and method for realizing network address translator traversal
US9413590B2 (en) Method for management of a secured transfer session through an address translation device, corresponding server and computer program
CN101904155A (en) Method of facilitating IP connections to hosts behind middleboxes
JP2022052742A (en) Method and system for enhancing communication between ipv6 dedicated sip client and ipv4 dedicated server or client
Tseng et al. Can: A context-aware NAT traversal scheme
Srirama et al. Tcp hole punching approach to address devices in mobile networks
WO2017161866A1 (en) Network connection method and device
US20230291706A1 (en) Method for accessing network, media gateway, electronic device and storage medium
CN112019641B (en) Data transmission method and device
US20180063255A1 (en) Method and Apparatus for Terminal Application Accessing NAS
US8812694B2 (en) Dialog establishment over a peer-to-peer architecture
CN112637382B (en) Data sending method and device, and method and system for establishing P2P connection
CN108337331B (en) Network penetration method, device and system and network connectivity checking method
EP3044929B1 (en) A mobile-device based proxy for browser-originated procedures
EP2608488B1 (en) Dialog establishment over a peer-to-peer architecture
JP2010157857A (en) Vpn connection device, packet control method, and program
CN116781670A (en) Cloud service access method, virtual service device, system, electronic equipment and medium
CN103179091A (en) Method for session initiation protocol (SIP) terminal to pass through firewall

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP01 Change in the name or title of a patent holder
CP01 Change in the name or title of a patent holder

Address after: 519000 Room 102, 202, 302 and 402, No. 325, Qiandao Ring Road, Tangjiawan Town, high tech Zone, Zhuhai City, Guangdong Province, Room 102 and 202, No. 327 and Room 302, No. 329

Patentee after: Zhuhai Jinshan Digital Network Technology Co.,Ltd.

Address before: 519000 Room 102, 202, 302 and 402, No. 325, Qiandao Ring Road, Tangjiawan Town, high tech Zone, Zhuhai City, Guangdong Province, Room 102 and 202, No. 327 and Room 302, No. 329

Patentee before: ZHUHAI KINGSOFT ONLINE GAME TECHNOLOGY Co.,Ltd.