java中使用p2p连接进行文件传输
我想使用 p2p 连接传输文件。将有一个服务器或任何公共场所来共享 A 和 B 计算机信息以建立连接。
我已经使用 LAN 创建了 p2p 连接。但我的问题是 - 对于互联网,我如何检测两台计算机的 IP 地址以进行套接字编程?或任何其他选项,以便我可以在两台经常更改 IP 地址的计算机之间传输文件?
提前致谢。
i want transfer files using p2p connection. There will be a server or any common place to share both A and B computers information for establishing the connection.
I've created p2p connection using LAN.But my question is - for internet how can I detect the IP addresses of the 2 computers for socket programming ? or any other option so that I can transfer files between two computers which are connected with frequently changing IP address ?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JXTA 是一个可以为您做到这一点的框架。我写了一本名为 Practical JXTA 的书,可以在 Scribd 上在线阅读。它包含完整的代码示例。您想要使用版本 2.6 或 2.7。
如果您不想使用框架,则当远程边缘对等点连接到它时,您的中央对等点应该能够读取远程边缘对等点的 NAT 转换地址(请参阅 Socket#getRemoteSocketAddress()) 。但这对 TCP 没有帮助(为了简单起见)。如果您使用 UDP,那么您就有机会,因为一旦在 NAT 中打出 UDP 漏洞,许多对等方(通常)可以连接到它。
JXTA is a framework that can do that for you. I wrote a book called Practical JXTA which is available for reading online at Scribd. It contains complete code examples. You want to work with release 2.6 or 2.7.
If you don't want to use a framework, your central peer should be able to read the NAT-translated address of your remote edge peers, when they connect to it (see
Socket#getRemoteSocketAddress()
) . But that won't help with TCP (to make it simple). If you use UDP, then you stand a chance, because once a UDP hole is punched in a NAT, many peers can (usually) connect to it.