2

I am writing a program that requires two clients (peer-to-peer) to connect to each other without the use of any server whatsoever, even just in the matchmaking process. Both clients already know each others' public and private IPs. One or both clients may be behind a NAT. I cannot rely on IPv6.

The problem I am running into is that one client (let's call them A) must send the packet to the other (B) that punches a hole in A's NAT and passes though B's NAT which has already been punched. However, this requires that A knows the external port on B's NAT that B has punched through to, as B's local port behind the NAT cannot be used. In addition, B cannot discern this port from behind its NAT. Visual representation of my problem Is there any way to discern this port, or even just let B tell the NAT what port to use?

Thanks in advance.

P.S. I am using the version of .NET Unity uses, approximately 2.0.

P.P.S. If you have a solution that works with TCP, I'll take that too!

P.P.P.S. Or pretty much any protocol other than Http!

HalpPlz
  • 691
  • 4
  • 11
  • I know 4y have passed, however, this topic is still relevant. How about trying to send to each port of B's NAT. There are only 65356 possibilities. That way you can avoid using a public server completely. I am still learning about this technique and I haven't tried it my self yet, so I don't if this idea would work. – Daniel Bartov Jan 31 '21 at 05:21

1 Answers1

1

You must have a well known public server to negotiate between the 2 endpoints.

Here's a good implementation of this concept in c#: https://github.com/7wingfly/P2Pchat

Elya Livshitz
  • 404
  • 1
  • 6
  • 9