This is not a new subject anymore, people have spent a lot of time on this subject, but there is still no perfect solution.
NAT prevents us to connect to each other directly.
Let me try to explain it:
Just assume you have two peers A, B, which want to establish a connection.
In a real network environment, A and B will be both behind the NAT, so they cannot connect to other with the local area network IP address(such as 192.168.. or, 10.0..).
To solve the above problem, people try to fire a public servers(C) to get the public IP addresses of A and B.
(1) A connects to C, we can get A's public IP address from the C.
(2) B connects to C, we can get B's public IP address from the C.
(3) Then C sends A's public IP to B, sends B's public IP to A. After that, A and B get the public IP of each other.
(4) Then A and B can establish a connection with the public IPs.
But that depends on the NAT's implementation.
For some types of NAT implementation, the A and B's public IPs may change. The public IPs of A/B will keep unchanged only if the current connection is not disconnected, which means even if we exchange the A/B's public IPs to each other by Server C, A and B cannot connect to each other.
Explaining the NAT in detail may need a lot of words, please ref https://en.wikipedia.org/wiki/Network_address_translation. section "NAT implementation classifications".
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…