5

I'm writing a P2P application and would like to avoid the need for users to manually set up the port forwarding.

I'm a bit confused since there seem to be two different protocols to configure a NAT, UPnP/IGD and NAT-PMP. Which one should I use? Are they both supported by all NATs? Or should I support both to make sure that at least one of them will be supported by the NAT?

Jules Olléon
  • 6,733
  • 6
  • 37
  • 47

3 Answers3

5

NAT-PMP (now PCP) is an ietf draft, so should be the one that you implement. However, for the sake of compatibility, you should allow your application to silently fallback to UPnP/IGD, as not all NAT devices support PCP/NAT-PMP, and a lot of the older devices only support UPnP/IGD.

T0xicCode
  • 4,583
  • 2
  • 37
  • 50
1

Consider using STUN instead of either NAT-PMP or UPnP-IGD. It generally works everywhere, and will almost certainly work through large-scale service-provider NAT and NAT64.

Community
  • 1
  • 1
james woodyatt
  • 2,170
  • 17
  • 17
  • Does that require setting up a STUN server? The diagram on page six of the RFC suggests that. Can you confirm that STUN works for purely peer-to-peer networking? – Brent Jan 06 '22 at 08:39
0

Stick to UDP hole punching. It works on almost all routers except if both clients are behind 4G LTE networks (these often have random port allocation) and routers that block ALL UDP traffic. If you need to send data reliably, you can use reliable UDP.