How does peer2peer work through a router?

2019-02-07 10:11发布

问题:

How does one PC connect to another over the internet to another PC?

An example would be a program listening for connections on PC 1. PC 1 sits behind Router 1. PC 2 has a client program trying to connect to PC 1.

What is the correct technology/technique to use as the listening program in this situation?

回答1:

This article by Brian Ford explains how peer to peer communication across NATs work.

Most routers also expose a Universal Plug and Play interface (uPnP) which can be used for port forwarding and NAT traversal.

You should also check out the STUNT library which is an easy to use NAT traversal library.



回答2:

You may want to read up on NAT Traversal. NAT traversal is a general term for techniques that establish and maintain TCP/IP network connections traversing network address translation (NAT) gateways.