network-programmingservernathandshakeupnp

How to structure P2P handshake WITH central server but WITHOUT relaying all of their traffic?


I have a Client A, and Client B, both behind some combinations of NATs, and I need them to make a P2P connection through TCP/UDP. Is there any way for me to use an external server, that those two clients could reliably reach, open up a socket with, then switch those opened sockets so that they will start communicating with each other instead?


Solution

  • There are several way to do it.

    1. NAT-PMP and UPNP may be the best choice, but the limitation is that if your NAT device doesn't support it, these will be uneffective.

    2. Using ICE structure can help you do it. But you need to know that NAT has four different types, and for symmetric NAT, we have to relay the streams from central server.