有4种NAT类型:
- Full cone NAT
- (Address) restrict cone NAT
- Port restrict cone NAT
- Symmetric NAT
打洞穿网需要两台Server:
- 信令Server,帮助客户机沟通IP:Port
- STUN Server,客户机判断自己所在NAT类型
STUN Server判断NAT类型步骤,参考下面链接:
UDP-P2P打洞穿网步骤,参考下面链接:
http://www.blogjava.net/linli/archive/2014/10/23/418968.html
下面这些情况下可以UDP-P2P打洞穿网:
- Full cone NAT -> Full cone NAT
- Full cone NAT -> (Address) restrict cone NAT
- Full cone NAT -> Port restrict cone NAT
- Full cone NAT -> Symmetric NAT
- (Address) restrict cone NAT -> Full cone NAT
- (Address) restrict cone NAT -> (Address) restrict cone NAT
- (Address) restrict cone NAT -> Port restrict cone NAT
- (Address) restrict cone NAT -> Symmetric NAT
- Port restrict cone NAT -> Full cone NAT
- Port restrict cone NAT -> (Address) restrict cone NAT
- Port restrict cone NAT -> Port restrict cone NAT
- Symmetric NAT -> Full cone NAT
- Symmetric NAT -> (Address) restrict cone NAT
下面这几种情况不可以UDP-P2P打洞穿网:
- Port restrict cone NAT -> Symmetric NAT
- Symmetric NAT -> Port restrict cone NAT
- Symmetric NAT -> Symmetric NAT