A NAT traversal method and system suitable for UDP communication of mobile games

The NAT type of mobile game devices is determined through the STUN server and NAT cross-border connection is performed using the port guessing algorithm, which solves the problem of low UDP communication efficiency between devices in mobile games and realizes efficient and reliable point-to-point communication.

CN116155855BActive Publication Date: 2025-04-25YONGSHI WANGLUO
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310175290.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-28
Publication Date
2025-04-25
Estimated Expiration
2043-02-28

AI Technical Summary

Technical Problem

The prior art is difficult to realize direct UDP communication between devices without public IP in mobile games, resulting in low communication efficiency, large latency and high server bandwidth cost.

Method used

The NAT device type of each node is determined through the STUN server, and NAT cross-border connection is performed according to the preset connection policy and port guessing algorithm to realize direct UDP communication between nodes.

Benefits of technology

It improves NAT travel efficiency and reliability between mobile game clients, realizes efficient point-to-point UDP communication, and reduces server bandwidth costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116155855B_ABST
    Figure CN116155855B_ABST
Patent Text Reader

Abstract

The present invention proposes a NAT traversal method suitable for UDP communication of mobile games, which includes the following steps: in response to each node that needs to be directly connected determining its own NAT device type through a STUN server, and then sending it back to the game server uniformly; after confirming the NAT type of each node, classify and process according to the NAT type of each node, and connect the nodes according to a preset connection strategy. By using the STUN server to judge and forward information such as the node NAT type, each node performs NAT traversal connection with each other through a preset strategy and algorithm based on the received NAT type and other information. This solution is aimed at the point-to-point NAT traversal problem of mobile game clients. Each client is in a peer state, which mainly solves the application requirements of connecting N clients in pairs, and can achieve more efficient and reliable mobile game client NAT traversal.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of computer network communication, and in particular relates to a NAT traversal method and system suitable for UDP communication of mobile games. Background Art

[0002] With the rapid development of Internet technology and business, the allocatable IPv4 address space has been exhausted. NAT devices came into being, which not only alleviated the plight of insufficient IP address space, but also brought the benefits of hiding and protecting computers inside the network from external attacks. Therefore, NAT devices are very popular today. But at the same time, it also violates the design principles of the IP address structure model and the design principles of the basic network layered structure model. It has caused great obstacles to the direct communication of those P2P applications. Many applications such as real-time multimedia communication and gaming require that nodes behind NAT can communicate directly, so as to achieve the purpose of increasing the data packet transmission rate, reducing latency, and reducing server bandwidth cost expenditure.

[0003] The existing NAT traversal method uses a STUN server to detect the NAT type and sends information such as the NAT type, host address, and mapping address to the NAT traversal server. The NAT traversal server then determines the corresponding traversal strategy based on the NAT type detection results of the communicating parties' clients.

[0004] However, the downside of this approach is that it is out of touch with the actual application scenarios of gamers in their daily network environment. This approach is not optimized for UDP transmission, while game communication is mainly achieved through UDP connections. In addition, players are equal in the network, and designating a single device to assume the function of a network hub does not meet the definition of an equal relationship between players. Summary of the invention

[0005] In order to solve the problem of interconnection and communication between devices without public IP in the existing game network, the present invention provides a NAT traversal method and system suitable for mobile game UDP communication to solve the above-mentioned technical defects.

[0006] In a first aspect, the present invention proposes a NAT traversal method applicable to UDP communication of mobile games, the method comprising the following steps:

[0007] In response to each node that needs to be directly connected determining its own NAT device type through the STUN server, and then sending it back to the game server;

[0008] After confirming the NAT type of each node, the nodes are classified and processed according to the NAT type, and the nodes are connected according to the preset connection strategy.

[0009] Preferably, before nodes are connected according to a preset connection strategy, it further includes:

[0010] Determine whether it may be a random port allocation strategy. If so, directly use the port guessing algorithm to establish a connection.

[0011] More preferably, the port guessing algorithm includes:

[0012] If it is determined that Ps > P0 & |Ps - P0| < Pc, randomly guess ports in two adjacent segments of P0, and guess N segments from near to far. Otherwise, try according to P0 + K * T + 1;

[0013] Further determine whether the attempt according to P0 + K * T + 1 is successful. If so, establish a communication connection to complete normal communication. Otherwise, continue to randomly guess ports in two adjacent segments of P0, and guess N segments from near to far;

[0014] Further determine whether the guess of N segments from near to far is successful. If the guess is successful, establish a communication connection to achieve normal communication. Otherwise, guess the remaining unguessed ports one by one;

[0015] Further determine whether the guess of the remaining unguessed ports one by one is successful. If the guess is successful, establish a communication connection to achieve normal communication. Otherwise, it means that the hole punching fails;

[0016] Among them, Ps represents the port of the target obtained in the previous sampling of two samplings, P0 represents the port of the target obtained in the latter sampling of two samplings, Pc represents the value of the rule set by the administrator of the NAT, K represents the increment interval configured by the NAT device, T represents the number of times from the last successful allocation to the current request for allocation, and N represents the number of segments for allocating available ports.

[0017] More preferably, the value range of T is [x, y], where x > 1 and y < 9.

[0018] Preferably, the set types divided by the clients that need to be directly connected include:

[0019] T0: OPEN_INTERNET, FULL_CONE, RESTRICTED_CONE, PORT_RES TRICTED_CONE;

[0020] T1: OPEN_INTERNET, FULL_CONE, RESTRICTED_CONE;

[0021] T2: SYMMETRIC;

[0022] T3: NET_UNKNOWN, UDP_BLOCKED, SYMMETRIC_UDP_FIREWAL L;

[0023] T4:PORT_RESTRICTED_CONE.

[0024] Further preferably, the preset connection strategy includes:

[0025] Connection strategy 1: If there is a T3 client in a game, the direct connection will be abandoned;

[0026] Connection strategy 2: If there are more than one T2 type clients among the clients, try to connect using the port guessing algorithm first. If the connection fails, give up the direct connection directly.

[0027] Connection strategy 3: If there is a client of type T2 and the remaining clients are not all of type T1, the port guessing algorithm is tried first. If it fails, the direct connection is abandoned.

[0028] Connection strategy 4: other types of clients try to connect directly.

[0029] Further preferably, the guessing hole-punching method includes:

[0030] One-way hole punching, T4 type client connects to T2 type client:

[0031] T2 sends 15054 to T4, ensuring that T2 has opened a hole for T4. Then T4 needs to use a guessing algorithm to guess the endpoint of the hole that T2 has opened for T4 before the hole on T2 becomes invalid.

[0032] T2 sends 15055 to the Server, which uses the Server to send a message to T4, telling T4 that T2 is ready to connect.

[0033] Server sends 15056 to T4, telling T4 that T2 is ready;

[0034] T4 uses a guessing algorithm to send 15058 to T2, probing each endpoint and ensuring that T4 has opened a hole for each probed endpoint of T2. After receiving message 15058, T2 changes its saved communication address of T4 to the sending address of 15058 and replies message 15057 to T4. After receiving 15057, T4 changes its saved communication address of T2 to the sending address of packet 15057.

[0035] T4 and T2 send 15053 to each other, and then receive 15053 from each other, which means the connection is successful.

[0036] Further preferably, bidirectional drilling is also included:

[0037] T4 and T2 use the guessing algorithm to send 15059 to each other. The first one to try will be discarded, but a hole is opened for the other party. When T2 tries, T4 can receive T2's message;

[0038] The party that receives the 15059 message first, T4, needs to change the communication address of T2 saved in its own storage to the sending address of the 15059 packet, and then send 15057 to T2;

[0039] After receiving packet 15057, T2 changes the communication address of T4 it has saved to the sending address of packet 15057;

[0040] T4 and T2 send 15053 to each other, and then receive 15053 from each other, which means they are successfully connected. After the successful connection, both parties will continue to send 15053 to maintain the hole.

[0041] In a second aspect, an embodiment of the present invention further provides a NAT traversal system suitable for UDP communication of mobile games, the system comprising:

[0042] The STUN server module is used to determine the NAT device type of each node that needs to be directly connected through the STUN server;

[0043] The game server module is used to determine the NAT device type of each node that needs to be directly connected through the STUN server, and then send it back to the game server;

[0044] A classification processing module is used to classify and process the NAT types of each node after confirming the NAT type of each node;

[0045] The connection strategy module is used to connect nodes according to a preset connection strategy.

[0046] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any implementation manner in the first aspect.

[0047] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any implementation manner in the first aspect.

[0048] Compared with the prior art, the beneficial results of the present invention are:

[0049] By using the STUN server to determine and forward information such as the node NAT type, each node uses preset strategies and algorithms to perform NAT traversal connections with each other based on the received NAT type and other information. This solution targets the point-to-point NAT traversal problem of mobile game clients. Each client is in a peer-to-peer state, which mainly solves the application requirements of N clients connected in pairs, and can achieve relatively efficient and reliable NAT traversal of mobile game clients. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] The accompanying drawings are included to provide a further understanding of the embodiments and are incorporated into and constitute a part of this specification. The accompanying drawings illustrate the embodiments and are used together with the description to explain the principles of the present invention. It will be easy to recognize other embodiments and many expected advantages of the embodiments because they become better understood by reference to the following detailed description. The elements of the drawings are not necessarily to scale with each other. The same reference numerals refer to corresponding similar parts.

[0051] Figure 1 is a diagram of an exemplary device architecture in which an embodiment of the present invention may be applied;

[0052] Figure 2 It is a flow chart of a NAT traversal method applicable to UDP communication of mobile games according to an embodiment of the present invention;

[0053] Figure 3 It is a flow chart of a port guessing algorithm in a NAT traversal method applicable to UDP communication of a mobile game according to an embodiment of the present invention;

[0054] Figure 4 A schematic diagram of a NAT traversal system for UDP communication of a mobile game according to an embodiment of the present invention;

[0055] Figure 5 It is a schematic diagram of the structure of a computer device suitable for implementing an electronic device of an embodiment of the present invention. DETAILED DESCRIPTION

[0056] In the following detailed description, reference is made to the accompanying drawings, which form a part of the detailed description and are shown by illustrative specific embodiments in which the present invention can be put into practice. To this end, directional terms, such as "top", "bottom", "left", "right", "up", "down", etc., are used with reference to the orientation of the figures described. Because the parts of the embodiments can be positioned in several different orientations, directional terms are used for the purpose of illustration and are by no means limiting. It should be understood that other embodiments may be utilized or logical changes may be made without departing from the scope of the present invention. Therefore, the following detailed description should not be adopted in a limiting sense, and the scope of the present invention is defined by the appended claims.

[0057] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0058] Figure 1 An exemplary system architecture 100 is shown to which a method for processing information or an apparatus for processing information according to an embodiment of the present invention can be applied.

[0059] like Figure 1 As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0060] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0061] The terminal devices 101 , 102 , and 103 may be various electronic devices with communication functions, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

[0062] The server 105 may be a server that provides various services, such as a background information processing server that processes the verification request information sent by the terminal devices 101, 102, and 103. The background information processing server may analyze the received verification request information and obtain a processing result (such as verification success information that indicates that the verification request is a legitimate request).

[0063] It should be noted that the method for processing information provided in the embodiment of the present invention is generally executed by the server 105, and accordingly, the device for processing information is generally set in the server 105. In addition, the method for sending information provided in the embodiment of the present invention is generally executed by the terminal devices 101, 102, 103, and accordingly, the device for sending information is generally set in the terminal devices 101, 102, 103.

[0064] It should be noted that the server can be hardware or software. When the server is hardware, it can be implemented as a distributed server cluster composed of multiple servers or as a single server. When the server is software, it can be implemented as multiple software or software modules (e.g., for providing distributed services), or as a single software or multiple software modules, and no specific limitation is made here.

[0065] Figure 2 The embodiments of the present invention disclose a NAT traversal method applicable to UDP communication of mobile games, as Figure 2 shown, the method includes the following steps:

[0066] S1. In response to determining the NAT device types of each node that needs to be directly connected through the STUN server, and then uniformly sending them back to the game server;

[0067] Specifically, the game server sends each node that needs to be directly connected this time and their basic information such as addresses and NAT device types to each node.

[0068] S2. After confirming the NAT types of each node, classify and process them according to the NAT types of each node, and determine whether it may be a random port allocation strategy. If so, directly use the port guessing algorithm for connection, and the nodes are connected according to the preset connection strategy.

[0069] Specifically, referring to Figure 3 , the port guessing algorithm includes:

[0070] If it is judged that Ps > P0 & |Ps - P0| < Pc, then randomly guess ports in two adjacent segments of P0, and guess N segments from near to far, otherwise try according to P0 + K * T + 1;

[0071] Further judge whether the attempt of P0 + K * T + 1 is successful. If so, it means that the hole punching is successful and normal communication is achieved. Otherwise, continue to randomly guess ports in two adjacent segments of P0, and guess N segments from near to far;

[0072] Further judge whether the guess of N segments from near to far is successful. If the guess is successful, perform a communication connection to achieve normal communication. Otherwise, guess each remaining unguessed port one by one;

[0073] Further judge whether the guess of each remaining unguessed port one by one is successful. If the guess is successful, perform a communication connection to achieve normal communication. Otherwise, it means that the hole punching fails;

[0074] Among them, Ps represents the port of the target obtained in the first of two samplings, P0 represents the port of the target obtained in the second of two samplings, Pc represents the value of the rule set by the NAT administrator, K represents the increment interval configured by the NAT device, T represents the number of times from the last successful allocation to the current allocation request, and the value range of T is [x, y], where x>1, y<9, and N represents the number of segments that can be allocated to the port.

[0075] In this embodiment, the value range of T is [2,9].

[0076] Pc: (65535-1024)2 = 32256. If you know the rules set by the NAT administrator, you can use different values, or you can use a common value. 1024 represents the port occupied by common services;

[0077] K: If it is set to 50, it means that we guess that the current hole-punching NAT device is configured by the NAT device administrator in the G1 policy, and the increment interval is less than 50;

[0078] T: In reality, there may be multiple application requests for allocation behind the NAT device. We define a T to represent how many times NAT has allocated for other requests from the last successful allocation to this request. You can try different values.

[0079] For example, assuming that T takes a fixed value of 1 and K takes a fixed value of 50, then the network will try to connect P0+1*0+1, P0+1*1+1, P0+1*2+1...P0+1*50+1; assuming that T takes a range value of [2,4] and K takes a fixed value of 50, then the network will try to connect P0+2*0+1, P0+2*1+1, P0+2*2+1...P0+2*50+1, P0+2*0+1, P0+2*1+1, P0+2*2+1...P0+2*50+1, P0+3*0+1, P0+3*1+1, P0+3*2+1..P0+3*50+1, P0+4*0+1, P0+4*1+1, P0+4*2+1...P0+4*50+1.

[0080] NMax: How many segments are the allocable ports to be divided into? Assuming 400 is used here, then (65535-1024)400 rounded up can be calculated as 162 ports in one segment. N can be set by yourself.

[0081] If N is 1, then it will try to connect P0-162, P0-161, ..., P0-1, P0+1, ..., P0+162. Of course, it is necessary to remove the guesses made in the previous step, and at the same time, the polling method makes the above value finally fall within (1024.65535); if N is 3, then it will try to connect P0+162, P0-161, ..., P0-1, P0+1, ..., P0+162 from near to far. ..., P0+162, P0-162*1-162, P0-162*1-161, ..., P0-162*1-1, P0+162*1+1, P0+162*1+16 2. ..., P0-162*2-162, P0-162*2-161, ..., P0+162*2-1, P0-162*2+1, ..., P0+162*2+162.

[0082] Further, assume that: the allocated port range is between (2014, 65535), and these ports are divided into 400 segments;

[0083] Ps: the port used when the player logged in, and the port recorded in the last NAT connection when the player makes a UDP communication NAT connection each time he plays the game; P0: the port obtained by the player from the STUN server for this NAT connection; k: k allocations occurred on NAT from obtaining P0 to the client attempting a NAT connection;

[0084] G1: Guessing method 1, the port is P0+k*T (T>=1);

[0085] G2: Guessing method 2, the port is near the last allocated port, which is considered to be within 12 segments in this embodiment;

[0086] G3: Guessing method 3, the ports are completely randomly distributed, directly randomizing all ports;

[0087] The specific algorithm is as follows:

[0088] 1. If Ps>P0 and |Ps-P0|<31760, it is most likely not the G1 mode. In this case, execute step 2.

[0089] Specifically, incremental allocation is usually adopted. P0 is generally greater than Ps. However, there are 65535 ports that can be mapped by NAT in total. Ports 0-2014 are generally reserved for more important general services, such as http, ftp and other protocols. When ports 65535-2014 are allocated, they will be reallocated from the port number near 2015. Therefore, check |Ps-P0|<(65535-2014) / 2 and round it up. This is to use the existing conditions to determine the least likely situation of G1. Here, 2014 can be written as a variable such as X, as the configuration of this hole punching algorithm, and the default value can be set to 2014.

[0090] 2.2.1. Estimate the size of k. K is related to the usage and access volume in the NAT. Here we just take 50. If you estimate, the value should not be greater than 254.

[0091] 2.2. Start from port P0 and try to establish a NAT connection by increasing the number by 1 until k times of failure. Then go to step 2.3. If the NAT connection is successfully established in the middle, go to step 4.

[0092] 2.3.T takes the value from [2,9] and performs the operation in 2.2. After a maximum of 8*k failures, perform 2.3. If the NAT connection is successfully established, perform step 4.

[0093] 3.3.1. Try G2, because it is more likely than G3. Randomly guess the port in the two adjacent segments of P0, and guess 12 segments from near to far. If the NAT connection fails to be established, go to 3.2. If successful, go to step 4.

[0094] Specifically, the random guessing of ports can filter out the ones guessed in step 2, and the final guessed ports are mapped to [2015, 65535] in a round-robin manner. Guessing from near to far includes G3 itself, and all ports are guessed, or the guessing timeout set by the call is reached before exiting.

[0095] 3.2. Guess all ports in the remaining fields. If successful, proceed to step 4. If failed, proceed to step 5.

[0096] 4. The NAT connection is established successfully and UDP direct connection is executed;

[0097] 5. If the NAT connection fails to be established, re-execute the port guessing process. After three consecutive steps of step 5, exit the process and stop guessing.

[0098] Specifically, the complete process of the hole drilling operation:

[0099] Assume that B is a server with a public IP, and A and C are hosts behind two different NATs. When A and C need to communicate directly, the following operations are required:

[0100] A sends a request to B, and B records A's port and IP;

[0101] C sends a request to B, and B records C's port and IP;

[0102] B sends A's port and IP to C, and C's port and IP to A;

[0103] A sends data to the port and IP of C sent by B. At this time, the data will be rejected by C, but A's NAT device will record that A and C have communicated;

[0104] C performs the same operation as A, but the difference is that since A's NAT device has recorded the communication between A and C, A's NAT device will not intercept C's data, so C can communicate with A. At the same time, since C has also sent data to A, the next data sent by A to C will not be intercepted by C's NAT device. In this way, A and C can communicate normally, and a hole punching process is completed.

[0105] Guessing hole punching methods include:

[0106] One-way hole punching, T4 type client connects to T2 type client:

[0107] T2 sends 15054 to T4, ensuring that T2 has opened a hole for T4. Then T4 needs to use a guessing algorithm to guess the endpoint of the hole that T2 has opened for T4 before the hole on T2 becomes invalid.

[0108] T2 sends 15055 to the Server, which uses the Server to send a message to T4, telling T4 that T2 is ready to connect.

[0109] Server sends 15056 to T4, telling T4 that T2 is ready;

[0110] T4 uses a guessing algorithm to send 15058 to T2, probing each endpoint and ensuring that T4 has opened a hole for each probed endpoint of T2. After receiving message 15058, T2 changes its saved communication address of T4 to the sending address of 15058 and replies message 15057 to T4. After receiving 15057, T4 changes its saved communication address of T2 to the sending address of packet 15057.

[0111] T4 and T2 send 15053 to each other, and then receive 15053 from each other, which means the connection is successful.

[0112] Also includes bidirectional punching:

[0113] T4 and T2 use the guessing algorithm to send 15059 to each other. The first one to try will be discarded, but a hole is opened for the other party. When T2 tries, T4 can receive T2's message;

[0114] The party that receives the 15059 message first, T4, needs to change the communication address of T2 saved in its own storage to the sending address of the 15059 packet, and then send 15057 to T2;

[0115] After receiving packet 15057, T2 changes the communication address of T4 it has saved to the sending address of packet 15057;

[0116] T4 and T2 send 15053 to each other, and then receive 15053 from each other, which means they are successfully connected. After the successful connection, both parties will continue to send 15053 to maintain the hole.

[0117] The direct connection scheme between nodes is shown in the following table:

[0118]

[0119]

[0120] Furthermore, the types of sets that require direct client connection include:

[0121] T0:OPEN_INTERNET,FULL_CONE,RESTRICTED_CONE,PORT_RES TRICTED_CONE;

[0122] T1:OPEN_INTERNET,FULL_CONE,RESTRICTED_CONE;

[0123] T2:SYMMETRIC;

[0124] T3:NET_UNKNOWN,UDP_BLOCKED,SYMMETRIC_UDP_FIREWAL;

[0125] T4:PORT_RESTRICTED_CONE;

[0126] The preset connection strategies include:

[0127] Connection strategy 1: If there is a T3 client in a game, the direct connection will be abandoned;

[0128] Connection strategy 2: If there are more than one T2 type clients, try strategy 5 first. If the connection fails, give up the direct connection.

[0129] Connection strategy 3: If there is one client of type T2 and the remaining clients are not all of type T1, then strategy 5 is tried first. If it fails, the direct connection is abandoned.

[0130] Connection strategy 4: other types of clients try to connect directly;

[0131] Finally, the two client connections can be summarized into the following two ways:

[0132] Method 1: Client1 (T0) connects to Client2 (T0): Client1 and Client2 send 15053 to each other at regular intervals. The first 15053 may not be received by each other, but if the NAT connection is successfully established, it can be predicted that the second or subsequent 15053 will be received by the other party from some point on.

[0133] Method 2: Client1(T1) connects to Client2(T2):

[0134] Step 1: Client 1 (T1) sends 15054 to Client 2 (T2), ensuring that Client 1 opens a hole for Client 2;

[0135] Step 2: Client 1 (T1) sends 15055 to the Server, which uses the Server to send a message to Client 2, notifying Client 2 that "Client 1 is ready to connect";

[0136] Step 3: Server sends 15056 to Client 2 (T2), telling Client 2 that Client 1 is ready.

[0137] Step 4: Client2 (T2) sends 15057 to Client1 (T1), ensuring that Client2 opens a hole for Client1. After receiving the message, Client1 (T1) changes the communication address of Client2 (T2) saved in its own storage to the sender address of the 15057 packet;

[0138] Step 5: Client1 (T1) and Client2 (T2) send 15053 to each other, and then receive 15053 from each other, which means the connection is successful.

[0139] Connection strategy 5, guess connection.

[0140] Describe its behavior from the perspective of port allocation:

[0141] Allocation method 1: 'port sensitive' allocation

[0142] Allocation method 2: 'address sensitive' allocation

[0143] Allocation method 3: incremental allocation

[0144] Create new bindings by rotating ports from a port range. For example, if you use the port range 0xC000-0xCFFF, then in most cases, select the port mode: 0xC000, 0xC001, 0xC002......0xCFFE, 0xCFFF, 0xC000, 0xC001......;

[0145] Allocation method 4: Random ("queued resource allocation")

[0146] Typically: a predetermined number of ports are queued. In FIFO fashion, a port is queued when a bind occurs, and is put back into the queue when an unbind occurs. Ports are difficult to predict.

[0147] In a specific embodiment, suppose that two clients A and B try to connect directly, and that they are both T2 type, and that the policy of the NAT devices of A and B is address sensitive, i.e., "allocation mode 2", then first they send both IPA and IPB to each other through our game server. At this time, A and B both start to send 15059 protocol to each other, and suppose that PortA0 is allocated when IPA connects with STUN, and that T=3 allocations have occurred when IPA sends 15059 to IPB, and that the allocation interval of the NAT device where IPA is located is k=2, then the port of the hole that IPA makes on NAT for IPB is PortA0+2*3.

[0148] Similarly, suppose IPB sends 15059 to IPA, causing a hole PortB0+5*3 to be punched for IPA on the NAT where IPB is located. Then A and B both make the above guesses. If they are lucky, A will guess that k=2T=3, or B will guess that k=5,T=3 before the NATs of both parties reclaim the holes they have punched for each other. It depends on who of them forwards 15059 to the other party through the hole reserved by the other party first. Assuming that A is lucky enough to send 15059 to B through the hole PortB0 reserved for A by B first, at this time, B will set the port of A for communication with A to the port carried by the packet 15059, that is, PortA0+2*3, and B will stop punching holes.

[0149] Then B will send a 15057 packet back to IPA, PortA0+2*3 (to prevent packet loss, it can be sent once in a while), and this 15057 will be sent to A through the hole that A left for B on NAT. After receiving it, A will change B's address and port to IPB, PortB0+5*3 brought by 15057, and then A will terminate its own hole. After that, A and B can normally communicate over UDP through the 5-tuple {udp,IPA,PortA0+2*3,IPB,PortB0+5*3}.

[0150] In a second aspect, an embodiment of the present invention further discloses a NAT traversal system suitable for UDP communication of mobile games, such as Figure 4 As shown, the system includes: a STUN server module 41, a game server module 42, a classification processing module 43 and a connection strategy module 44.

[0151] In a specific embodiment, the STUN server module 41 is used to determine the NAT device type of each node that needs to be directly connected through the STUN server; the game server module 42 is used to determine the NAT device type of each node that needs to be directly connected through the STUN server, and then send it back to the game server; the classification processing module 43 is used to classify and process each node according to the NAT type after confirming the NAT type of each node; the connection strategy module 44 is used to connect between nodes according to a preset connection strategy.

[0152] By using the STUN server to determine and forward information such as the node NAT type, each node uses preset strategies and algorithms to perform NAT traversal connections with each other based on the received NAT type and other information. This solution targets the point-to-point NAT traversal problem of mobile game clients. Each client is in a peer-to-peer state, which mainly solves the application requirements of N clients connected in pairs, and can achieve relatively efficient and reliable NAT traversal of mobile game clients.

[0153] Reference below Figure 5 , which shows an electronic device (eg Figure 1 A schematic diagram of the structure of a computer device 500 (a server or terminal device as shown). Figure 5 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0154] like Figure 5As shown, the computer device 500 includes a central processing unit (CPU) 501 and a graphics processing unit (GPU) 502, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 503 or the program loaded from the storage part 509 to the random access memory (RAM) 506. In the RAM 504, various programs and data required for the operation of the device 500 are also stored. The CPU 501, GPU 502, ROM 503 and RAM 504 are connected to each other through a bus 505. An input / output (I / O) interface 506 is also connected to the bus 505.

[0155] The following components are connected to the I / O interface 506: an input section 507 including a keyboard, a mouse, etc.; an output section 508 including a display such as a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 509 including a hard disk, etc.; and a communication section 510 including a network interface card such as a LAN card, a modem, etc. The communication section 510 performs communication processing via a network such as the Internet. A drive 511 can also be connected to the I / O interface 506 as needed. A removable medium 512, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 511 as needed, so that a computer program read therefrom is installed into the storage section 509 as needed.

[0156] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 510, and / or installed from the removable medium 512. When the computer program is executed by the central processing unit (CPU) 501 and the graphics processing unit (GPU) 502, the above-mentioned functions defined in the method of the present invention are executed.

[0157] It should be noted that the computer-readable medium described in the present invention may be a computer-readable signal medium or a computer-readable medium or any combination of the above two. The computer-readable medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor device, apparatus or device, or any combination of the above. More specific examples of computer-readable media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution device, apparatus or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium may also be any computer-readable medium other than a computer-readable medium that can send, propagate or transmit a program for use by or in conjunction with an instruction execution device, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0158] Computer program code for performing the operations of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0159] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the device, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based device that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0160] The modules involved in the embodiments of the present invention may be implemented in software or hardware, and the modules described may also be arranged in a processor.

[0161] As another aspect, the present invention also provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by the electronic device, the electronic device: responds to each node that needs to be directly connected to determine its own NAT device type through the STUN server, and then sends it back to the game server uniformly; after confirming the NAT type of each node, classify and process according to the NAT type of each node, and connect the nodes according to the preset connection strategy.

[0162] The above description is only a preferred embodiment of the present invention and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present invention is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above inventive concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present invention (but not limited to) to form a technical solution.

Claims

1. A NAT traversal method suitable for UDP communication of mobile games, characterized in that: The method is applied to interconnect and communicate between mobile gaming devices without public IP in a gaming network, and the method comprises the following steps: In response to each node that needs to be directly connected determining its own NAT device type through the STUN server, and then uniformly sending it back to the game server, wherein the node sends a request data packet containing mobile game specific identification information to the STUN server, and the STUN server determines the NAT type of the node according to its own detection mechanism and the identification information, and then uniformly sends the NAT type back to the game server in a specific format and protocol suitable for mobile games, wherein the specific format and protocol are to better adapt to the mutual connection and communication between mobile game devices; After confirming the NAT type of each node, the nodes are classified and processed according to the NAT type of each node, and the nodes are connected according to a preset connection strategy, including the NAT type classification of each node considering the resource consumption and real-time communication requirements of the mobile game node, and the NAT type nodes with large resource consumption are classified using an optimized resource allocation strategy, and the nodes are connected according to a preset connection strategy considering the instability of the mobile game network and limited device resources; Among them, the set types of clients that need to be directly connected include: T0: OPEN_INTERNET, FULL_CONE, RESTRICTED_CONE, PORT_RESTRICTED_CONE; T1: OPEN_INTERNET, FULL_CONE, RESTRICTED_CONE; T2: SYMMETRIC; T3: NET_UNKNOWN, UDP_BLOCKED, SYMMETRIC_UDP_FIREWALL; T4: PORT_RESTRICTED_CONE; and also include judging whether it may be a random port allocation strategy. If so, directly use the port guessing algorithm to connect, and the port guessing algorithm includes: If it is judged that Ps > P0 & |Ps - P0| < Pc, then randomly guess the ports in two adjacent segments of P0, and guess N segments from near to far. Otherwise, try according to P0 + K * T + 1; further judge whether the attempt of P0 + K * T + 1 is successful. If it is successful, establish a communication connection to complete normal communication. Otherwise, continue to randomly guess the ports in two adjacent segments of P0 and guess N segments from near to far; further judge whether the guess of N segments from near to far is successful. If the guess is successful, establish a communication connection to achieve normal communication. Otherwise, guess each of the remaining unguessed ports one by one; further judge whether the guess of each of the remaining unguessed ports one by one is successful. If the guess is successful, establish a communication connection to achieve normal communication. Otherwise, it means that the hole punching fails; where Ps represents the port of the target obtained in the previous sampling of the two samplings, P0 represents the port of the target obtained in the latter sampling of the two samplings, Pc represents the value of the rule set by the administrator of the NAT, K represents the increasing interval configured by the NAT device, T represents the number of times from the last successful allocation to the current request for allocation, and N represents the number of segments of the allocable ports; the value range of T is [x, y], where x > 1 and y < 9; The preset connection strategies include: Connection Strategy 1: If there is a T3 type in the client of a game, directly abandon direct connection; Connection Strategy 2: If the number of T2 type clients in the client is more than 1, first try to connect using the port guessing algorithm of Connection Strategy 5. If the connection fails, directly abandon direct connection; Connection Strategy 3: If there is one client belonging to the T2 type and the other remaining clients are not all of the T1 type, first try to connect using the port guessing algorithm of Connection Strategy 5. If it fails, abandon direct connection; Connection Strategy 4: Try direct connection for other types of clients; Connection Strategy 5: Directly use the port guessing algorithm for connection.

2. The NAT traversal method for mobile game UDP communication according to claim 1, characterized in that: The ways of guessing hole punching include: Unidirectional hole punching, where a T4 type client connects to a T2 type client: T2 sends 15054 to T4 to ensure that T2 opens a hole for T4. Then T4 needs to correctly guess the endpoint of the hole punched by T2 for T4 using the guessing algorithm before the hole on T2 becomes invalid; T2 sends 15055 to the Server, and the Server sends a message to T4 on behalf of T2, telling T4 that T2 is ready to implement the connection; The Server sends 15056 to T4 to relay the message that T2 is ready; T4 sends 15058 to T2 using the guessing algorithm to probe each endpoint and ensure that T4 opens a hole for each probed endpoint of T2. After receiving the message 15058, T2 changes the communication address of T4 it stores to the sending address of 15058 and returns the message 15057 to T4. After receiving 15057, T4 changes the communication address of T2 it stores to the sending end address of the 15057 packet; T4 and T2 send 15053 to each other, and after receiving 15053 from each other, it represents a successful connection.

3. The NAT traversal method for mobile game UDP communication according to claim 2, characterized in that: It also includes bidirectional hole punching: T4 and T2 respectively send 15059 to each other using the guessing algorithm. The first one to guess correctly will be discarded, but it opens a hole for the other party. When T2 guesses correctly, T4 can receive the message from T2; The party that receives the 15059 message first, T4, needs to change the communication address of T2 saved in its own storage to the sending address of the 15059 packet, and then send 15057 to T2; After receiving packet 15057, T2 changes the communication address of T4 it has saved to the sending address of packet 15057; T4 and T2 send 15053 to each other, and then receive 15053 from each other, which means they are successfully connected. After the successful connection, both parties will continue to send 15053 to maintain the hole.

4. A NAT traversal system suitable for UDP communication of mobile games, characterized in that: The system is applied to interconnect and communicate between mobile gaming devices without public IP in a gaming network, and the system includes: The STUN server module is used to determine the NAT device type of each node that needs to be directly connected through the STUN server; The game server module is used to determine the NAT device type of each node that needs to be directly connected through the STUN server, and then send it back to the game server in a unified manner, wherein the node sends a request data packet containing mobile game specific identification information to the STUN server, and the STUN server determines the NAT type of the node according to its own detection mechanism and the identification information, and then sends the NAT type back to the game server in a unified manner according to a specific format and protocol suitable for mobile games. The specific format and protocol are to better adapt to the mutual connection and communication between mobile game devices; A classification processing module is used to classify and process the NAT types of each node after confirming the NAT type of each node, including classifying and processing the NAT types of each node according to the resource consumption and real-time communication requirements of the mobile game node, and classifying the NAT type nodes with large resource consumption by adopting an optimized resource allocation strategy; A connection strategy module is used to connect nodes according to a preset connection strategy, which takes into account the instability of the mobile game network and the limited device resources. Among them, the set types of clients that need to be directly connected include: T0: OPEN_INTERNET, FULL_CONE, RESTRICTED_CONE, PORT_RESTRICTED_CONE; T1: OPEN_INTERNET, FULL_CONE, RESTRICTED_CONE; T2: SYMMETRIC; T3: NET_UNKNOWN, UDP_BLOCKED, SYMMETRIC_UDP_FIREWALL; T4: PORT_RESTRICTED_CONE; and also include judging whether it may be a random port allocation strategy. If so, directly use the port guessing algorithm to connect, and the port guessing algorithm includes: If it is determined that Ps > P0 & |Ps - P0| < Pc, then randomly guess the ports in two adjacent segments of P0, starting from the nearer one and guessing N segments. Otherwise, try according to P0 + K * T + 1; further determine whether the attempt of P0 + K * T + 1 is successful. If it is, establish a communication connection to complete normal communication. Otherwise, continue to randomly guess the ports in two adjacent segments of P0, starting from the nearer one and guessing N segments; further determine whether the guess of N segments from the nearer one is successful. If it is, establish a communication connection to achieve normal communication. Otherwise, guess the remaining unguessed ports one by one; further determine whether the guess of the remaining unguessed ports one by one is successful. If it is, establish a communication connection to achieve normal communication. Otherwise, it indicates that the hole punching fails; where Ps represents the port of the target obtained in the previous sampling of two samplings, P0 represents the port of the target obtained in the latter sampling of two samplings, Pc represents the value of the rule set by the administrator of the NAT, K represents the increasing interval configured by the NAT device, T represents the number of times from the last successful allocation to the current request for allocation, and N represents the number of segments for allocating the allocable ports; the value range of T is [x, y], where x > 1 and y < 9; The preset connection strategy includes: Connection strategy 1: If there is a T3 type in the client of a game, directly give up direct connection; Connection strategy 2: If the number of T2 type clients in the client is more than 1, first try to connect using the port guessing algorithm of connection strategy 5. If the connection fails, directly give up direct connection; Connection strategy 3: If there is one client belonging to the T2 type and the other remaining clients are not all of the T1 type, first try to connect using the port guessing algorithm of connection strategy 5. If it fails, give up direct connection; Connection strategy 4: Try direct connection for other types of clients; Connection strategy 5: Directly use the port guessing algorithm for connection.

5. An electronic device, comprising: One or more processors; A storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 3.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by the processor, it implements the method according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • UDP-based method and system for penetrating through NAT equipment

    CN101938532A