UDP Holepunching behind NAT

前端 未结 3 660
独厮守ぢ
独厮守ぢ 2021-01-31 06:21

I am trying to implement a simple sketch of UDP-Holepunching in Java to test it\'s concept and use it in my C/C++ application later on.

Concept:

As from Wikip

相关标签:
3条回答
  • 2021-01-31 06:37

    Given your conceptual outline, I think there is an issue at point 4. Although A punches a hole through its own NAT, when B attempts to reach this hole it is unaware of the port on A's NAT (or more correctly/commonly - NAPT) and hence A's NAT drops the packet when B attempts to communicate.

    0 讨论(0)
  • 2021-01-31 06:47

    Just a note for those following this great post, notice that in the server side, the second UDP packet received is announced as: System.out.println("(2nd) Server received:" + new String(bytes) + " from " + address1 + " on port " + port1); It should be System.out.println("(2nd) Server received:" + new String(bytes) + " from " + address2 + " on port " + port2); Its no big deal since its only an informative message, but it made me lose some time just wondering how the hell on earth the router was giving the same port to 2 different communications :P

    0 讨论(0)
  • 2021-01-31 06:55

    Your code seems to be correct. I tested your code and it works fine. The concept is also correct. But please check whether both the clients you run are within same NAT device or different NAT devices. If your are running both the clients under same NAT device then it may not work because not all NAT devices support hair pinning i.e, both clients send packets to NAT's external IP which needs to be passed to itself. For more information refer this link: http://tools.ietf.org/html/rfc4787#section-6

    0 讨论(0)
提交回复
热议问题