java通信协议
我即将通过互联网上的 tcp/ip 实现服务器/客户端通信。服务器和客户端在尝试同步状态时会有点吵闹。
client: sends state
server: check state and request differences
client: sends 1 element
server: sends ack/nak
client: sends 1 element
server: sends ack/nak
.
.
.
etc.
实现这一点的最佳方法是什么?我应该使用原始套接字吗?我应该使用 2 个连接,每个方向一个吗?我应该使用框架吗?任何想法表示赞赏。
谢谢
编辑:当优先考虑大负载(千兆字节的数据)、稳定性和易于实施时,实现此目的的最佳方法是什么?
..顺便说一句,客户端和服务器之间没有区别。他们可以随时转换角色,并成为建立联系的人。
使用处理重新连接等的框架可能会很好。
I'm about to implement server/client communication via tcp/ip over the internet. The server and the client will be a bit chatty when trying to synchronize their states.
client: sends state
server: check state and request differences
client: sends 1 element
server: sends ack/nak
client: sends 1 element
server: sends ack/nak
.
.
.
etc.
What is the best way to implement this? Should I use raw Sockets? Should I use 2 connections, one for each direction? Should I use a framework? Any idea are appreciated.
Thanks
EDIT: What is the best way to implement this, when large load (gigabytes of data), stability and ease of implementation are prioritized?
.. and by the way there are no differents between the client and the server. They can shift role any time, and be the one to make the connection.
It could be nice to use a framework that handles reconnect etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果客户端和服务器都是 Java 程序,请考虑使用 的替代方案RMI:
它比尝试在套接字上实现您自己的协议更简单。
If both the client and the server are going to be Java programs, consider the alternative of using RMI:
It's simpler than trying to implement your own protocol on top of sockets.
从我的角度来看,这些目标暗示了使用稳定的框架而不是实现自定义解决方案。
研究 Java Web 服务(您可以通过 Google 搜索找到大量示例)并让客户端也公开服务器接口。
我会推荐 RESTful 而不是 SOAP 服务。
From my point of view these goals are hints to using a stable framework rather implementing a custom solution.
Look into Java web services (you can find plenty of examples by Googling) and have both the client expose a server interface as well.
I would recommend RESTful instead of SOAP services.