使用 UDP(数据报)在 Java 中实现 TCP
对于文件共享应用程序,我想使用 TCP/IP 套接字。但这不起作用,因为两个客户端都位于 NAT 后面。因此我必须使用UDP和打洞方法。
由于 UDP 不可靠,我必须实现类似 TCP 的协议。我不需要流。基于消息的协议就可以了。某处已经有免费的 Java 库了吗?如果没有,是否有一个抽象教程,如何实现这样的协议?
For a file sharing application I would like to use TCP/IP Sockets. But this doesn't work because both clients are behind NATs. Therefore I have to use UDP and the hole punching method.
Since UDP is not reliable, I have to implement a TCP-like protocol. I don't need streams. A message based protocol would be ok. Is there already a free Java library somewhere? If not, is there an abstract tutorial, how to implement such a protocol?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以实施 TCP 打洞,允许两个对等点在防火墙后面进行通信。
首先通过此链接
http://www.brynosaurus.com/pub/net/p2pnat/
然后如果需要进一步帮助,请更新问题。但是 TCP 打洞的问题是,它可以在市场上 60% 的路由器中成功,而 UDP 打洞则可以成功 80-90%。
也请查看此链接。http://stackoverflow.com/questions/917385/nat-traversal-with-java
You Can Implement TCP hole Punching that will allow two peer to communicate behind fire wall.
first go through this link
http://www.brynosaurus.com/pub/net/p2pnat/
and then update the question if need further help on this.But the problem with TCP hole punching is that it can be successful in 60% of router available in the market whereas UDP hole punching is 80-90% successful.
check out this link as well.http://stackoverflow.com/questions/917385/nat-traversal-with-java
如果您搜索基于 UDP 的面向消息的协议,我会考虑 TeleHash。还有可用的 Java 库。
如果您依赖于传输大量二进制数据,也许这是错误的选择,但基于流的协议无论如何可能是更好的选择。
If you search for a UDP-based message-oriented protocol, I'd consider TeleHash. There are also Java libraries available.
Maybe it's the wrong choice if you rely on high volumes of binary data to be transmitted, but then a stream-based protocol might be the better choice anyway.
有帮助吗?
http://www.syslog4j.org/
was it helpful?
http://www.syslog4j.org/