简体   繁体   English

以编程方式从已知的公共服务器遍历NAT

[英]NAT traversal from known public server programmatically

I have already done some research about NAT traversal, and got some suggestions from the web about the P2P applications. 我已经对NAT穿越进行了一些研究,并从Web上获得了有关P2P应用程序的一些建议。 But my case is somewhat different than one traditional P2P applications.I already have one public Server, i just need to access the devices behind NAT from the known public Server. 但是我的情况与传统的P2P应用有所不同,我已经有一个公共服务器,我只需要从已知的公共服务器访问NAT后面的设备即可。

The detail info about my case is as following: 有关我的案件的详细信息如下:

1.PC-A have public IP
2.PC-B is behind NAT, does not have public IP. In my case PC-A and PC-B is under full control.
3.PC-C is also behind NAT, and could be reached from PC-B

The question is that: 问题是:

  1. Is there any way so that i could build a tunnel between the public server PC-A and PC-B, so that i could reach PC-C from PC-A with TCP protocol(or even UDP)? 有什么办法可以在公共服务器PC-A和PC-B之间建立隧道,以便我可以使用TCP协议(甚至是UDP)从PC-A到达PC-C?
  2. It's worth noting that all should be done programmatically, especially in Java.Is there any library could do that? 值得注意的是,所有这些都应该以编程方式完成,尤其是在Java中。是否有任何库可以做到这一点?

Your PC-A is often called a 'relay' in P2P talk. 在P2P对话中,您的PC-A通常被称为“中继”。

The basic principle is that all peers behind firewalls (PC-B and PC-C in your case) establish outbound connections to PC-A. 基本原则是,防火墙后面的所有对等设备(在您的情况下为PC-B和PC-C)都建立与PC-A的出站连接。 PC-A then "links/bonds" the connections. 然后,PC-A“链接/绑定”连接。 Usually these connections are made over HTTP, which is firewall friendly. 通常,这些连接是通过HTTP进行的,这是防火墙友好的。 So for PC-B to talk to PC-C, a simplified sequence is: 因此,为了使PC-B与PC-C进行通信,简化的顺序为:

  • PC-B and PC-C both establish an HTTP connection to PC-A PC-B和PC-C都建立与PC-A的HTTP连接
  • PC-B signals to PC-A that it wants to send data to PC-C PC-B向PC-A发出信号,它希望将数据发送到PC-C
  • PC-B sends its data to PC-A on the outbound request PC-B根据出站请求将其数据发送到PC-A
  • PC-A forwards the data to PC-C on the synchronous response. PC-A根据同步响应将数据转发到PC-C。

Things get (very) complicated when you throw in 当您投入时,事情变得(非常)复杂

  • authentication 认证方式
  • security 安全
  • redundant relays 冗余继电器
  • connection timeouts, reliability, recovery, etc... 连接超时,可靠性,恢复等...

Most P2P frameworks implement some kind of relays. 大多数P2P框架都实现某种中继。 This is the case for JXTA and XMPP (check ICE). 对于JXTA和XMPP(检查ICE)就是这种情况。

I believe Ian Mc Ginniss also developed something called HTTP Tunnel as part of the Netty project (originally as replacement for JXTA relays which are somewhat sub-optimals) 我相信Ian Mc Ginniss在Netty项目中也开发了一个称为HTTP Tunnel的东西(最初是替代JXTA中继的,有些不太理想)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM