laitimes

Learn NAT types from online games

author:Bandits are invincible

Online game mode

Online game modes generally have server-based mode and P2P mode, and there are some differences between them, mainly including the following:

  1. Data transmission mode: In the server-based mode, game data is transmitted through the game server, and the data exchange between players is realized through the game server. In the P2P model, the data exchange between players is direct and does not need to go through the game server.
  2. Stability and latency: Since in server-based mode, all data transfer needs to go through the game server, stability and latency may be affected by the server. In the P2P model, the data exchange between players is direct, and the stability and latency may be better, but the compatibility and stability of the network environment and device configuration need to be ensured.
  3. Security and anti-cheating: In server-based mode, game servers can more strictly manage and monitor games to ensure game security and anti-cheating. In the P2P model, the exchange of data between players is direct and may be more vulnerable to attack or cheat.

Server-based mode and P2P mode are not mutually exclusive, in fact, many online games use a hybrid of the two modes, such as using a server for matchmaking and partial data transfer in the game, and using P2P mode for real-time data transfer between players.

Learn NAT types from online games

Server-base simple diagram

Learn NAT types from online games

P2P connection game simple diagram

In short: server-based mode is a server-to-many (Player) relationship, usually TCP link, P2P mode point-to-point (Player) relationship, usually UDP link.

Online Gaming Protocol

Many games use a mix of TCP and UDP to achieve networking, such as using TCP to transmit game data and commands, and using UDP to transmit real-time game operations. Generally speaking:

  1. TCP usage scenarios:
  • Game lobbies, matchmaking, and other scenarios that require frequent communication. TCP has the characteristics of strong reliability, no loss and no duplication of transmitted data, and is suitable for frequent communication scenarios, such as game lobbies, matchmaking, chat rooms, etc.
  • Scenarios where data transmission needs to be ensured. TCP has the characteristics of high reliability, flow control, and congestion control, and is suitable for scenarios that need to ensure the accuracy of data transmission, such as uploading and downloading game data and saving game progress.
  • Scenarios with a small amount of data. TCP has a relatively large header and low transmission efficiency, making it suitable for scenarios with a small amount of data, such as sending commands and requesting data.
  1. Usage scenarios of UDP:
  • Scenarios with high real-time requirements. UDP has the characteristics of fast transmission speed and high real-time performance, which is suitable for scenarios with high real-time requirements, such as movement, shooting and other operations in online games.
  • Scenarios for large amounts of data transfer. UDP does not have the characteristics of TCP traffic control and congestion control, but has the advantage of high transmission efficiency, which is suitable for scenarios with large amounts of data transmission, such as real-time audio and video transmission in games, battle screen rendering, etc.
  • Some scenarios for non-critical data transmission. UDP does not have the characteristics of strong reliability, no data loss, and no duplication, and is suitable for some non-critical data transmission scenarios, such as in-game statistics and advertisements.

Generally speaking, TCP is generally server-based, as long as the official uniform is strong enough, you will not have a bad experience. What affects the online experience is the P2P connection in UDP mode. So sometimes you feel that the matching is very fast, but the game card is a P, or the game fluency is not bad, but the save file can't be uploaded.

Due to the rarity of IP, it is impossible for everyone to have an independent IP, in general, our IPv4 access points are NAT translated, reducing the use of IP while increasing security (relatively). The above P2P connection diagram becomes the following:

Learn NAT types from online games

After NAT translation, different players cannot connect directly

Players are unable to discover each other, resulting in slow or even failed connections.

The effect of NAT type on connection quality

NAT type is an important factor affecting the quality of connectivity. Different types of NAT have different effects on connection quality.

  • NAT1 (Full Cone NAT): Good connection quality, fast P2P connection and data transmission. Above
  • NAT2 (Passable NAT): The connection quality is good, and P2P connection and data transmission can be realized, but the connection speed and stability may be affected to some extent.
  • NAT3 (Fully Symmetric NAT): Poor connection quality for P2P connectivity and data transfer. In the NAT3 network environment, additional technical means such as relay servers are required to establish connections.

When playing P2P online battles in games, a network environment with NAT type NAT2 is usually used, because NAT2 type is less restrictive and usually allows P2P communication between gamers without the use of relay servers or other technologies.

The NAT3 type has many restrictions, and there are certain restrictions on P2P communication, which requires the use of repeater servers or other technologies to penetrate, so the use of NAT3 type network environment in game online battles may cause slow connection speed or unstable connection problems.

There is also a NAT4 type, which is basically not related to P2P games and Junior JJ. So what is the difference between these NAT types?

Learn NAT types from online games

Oh my god

NAT, NAT2, NAT3, NAT4 difference

  • NAT (Open): This type of NAT, also known as Full Cone NAT, maps the IP address of the internal network to one or more public IP addresses and allows devices in the internal network to access the Internet. This type of NAT is relatively simple and does not have too many restrictions, so it is often referred to as "open NAT".
  • NAT2 (Moderate): This NAT type, also called Restricted Cone NAT, is similar to NAT, which maps all inbound packets to the same internal address and port, and records the address and port number of the sender. However, packets can only be forwarded to that address and port if they have been previously sent to that address and port. This type of NAT usually allows users to do basic P2P communication.
  • NAT3 (Strict): This type of NAT, also known as Symmetric NAT, restricts inbound traffic so that two devices behind different NATs cannot communicate directly. To solve this problem, it is necessary to use relay servers or other technologies to penetrate.
  • NAT4: This type of NAT, also known as Port Restricted Cone NAT, restricts inbound packets from IP addresses and port numbers that have previously sent packets to that address and port. This NAT type has certain restrictions on P2P communication.

Typically, home broadband is NAT3 mode. The use of dynamic independent IP is generally NAT1 (Open), you can call the operator to apply.

NAT2 can achieve limited P2P by punching holes, and the game online experience will be affected, but NAT3, when playing P2P games, is basically not connected, and in general, it is necessary to go to the accelerator to get good results.

With a dynamic standalone IP, NAT2 or NAT3?

After applying for an independent IP address, the NAT type is still 2 or 3. The reason is that routers, in general, use router dial-up, your router is NAT1, but the back of the router becomes NAT2. At this time, you need to do port mapping, and map the port on the router directly to the PS or Xbox to achieve NAT1.

There are three main scenarios:

  1. UPnP and NAT-PMP, both protocols for port mapping between network devices, are used to help applications penetrate between NAT devices, implement P2P connections and data transfers, their differences are:
  • Standards are different: UPnP is an open standard developed by the UPnP Forum, while NAT-PMP is a proprietary protocol developed by Apple.
  • Platform support is different: The UPnP protocol is widely supported, including different platforms such as Windows, Linux, and macOS, while NAT-PMP is only supported by Apple's operating system.
  • Transport methods are different: UPnP uses SOAP (Simple Object Access Protocol) and HTTP (Hypertext Transfer Protocol) for communication, while NAT-PMP uses the UDP protocol for communication.
  • Different port mapping methods: UPnP uses dynamic port mapping, that is, when an application needs to use a port, it will request a port mapping from the NAT device through the UPnP protocol, and the port mapping will be automatically released after use. NAT-PMP, on the other hand, uses static port mapping, that is, when an application needs to use a port, it needs to manually configure it on the NAT device in advance.

It should be noted that these two methods require the support of the game software itself, and most online games are built-in, which means that even NAT2 can successfully connect to the Internet.

The opening method takes ASUS router as an example:

Learn NAT types from online games

Select Full Cone for the NAT type and enable UPnP

  1. Manual mapping is basically not needed, but when streaming at PlayStation, it can be used if your router does not support UPnP. Because different games require different ports.
  2. Router advanced functions, here or take ASUS router as an example, he built-in a lot of port mapping required by the game, which is equivalent to manual mapping as a database, when different hosts are detected, mapped to different ports, so that even if the game does not support UPnP can NAT2 type.
Learn NAT types from online games

ASUS NAT mapping

If you liked this article, please give it a like. Dig a hole, next time you can talk about how to use Tailscale or headscale to break through the limitations of NAT2 or NAT3 and achieve remote Android development.