Java P2P 没有端口转发?
我一直在尝试找出一种无需使用端口转发或 VPN 服务即可建立 P2P 套接字连接的方法。
我知道 TCP/UDP“打洞”方法,但是,我不愿意为此目的在我的计算机上 24/7 设置和运行服务器(而且我的网络无论如何都位于 NAT 之后......)。
我正在考虑在主机连接到的 URL 上设置 servlet 代码,当客户端尝试连接时,它会要求 servlet 建立连接。
这是否合理和/或您可以帮助我开始(我以前从未编写过 servlet 代码)?
I've been trying to figure out a way to establish a P2P socket connection without using port forwarding or a VPN service.
I am aware of the TCP/UDP "hole punching" method, however, I am not willing to setup and run a server on my machine 24/7 for this purpose (besides my network is behind a NAT anyway...).
I was thinking about setting up servlet code on a URL that the host connects to, and when the client attempts to connect, it asks the servlet to establish the connection.
Is this plausible and/or could you help me get started (I have never written servlet code before)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有 servlet,那么它必须在服务器上 24/7 运行。因此,您只能在 TCP/UDP 打洞和使用 servlet 之间进行选择。
由于您位于 NAT 之后,您可能应该尝试通过多播来解决连接问题。只需让对等方就 IP 多播地址达成一致,并相互传达其私有 IP 地址即可。如果他们想建立直接的 TCP 连接,那应该就足够了。您不需要中央服务器/servlet。
If you have a servlet, then it must run on a server 24/7. So, you are only choosing between TCP/UDP hole punching and using a servlet.
Since you are behind a NAT, you probably should try to solve your connection issues via multicasting. Just have peers agree on an IP multicasting address and communicate their private ip address to each other. If they want to establish direct TCP connections, that should be enough. You don't need a central server/servlet.