用Java实现IM平台
如果用Java创建一个IM平台,哪种方式更好地实现客户端和服务器之间的通信? 我在想要么 RMI 要么只是一个套接字连接...
请建议,
谢谢
If creating an IM platform in Java, which would be a better way to implement communications between the clients and server?
I was thinking either RMI or just a socket connection...
Advice please,
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将使用直接套接字连接,使用众所周知的协议,例如 XMPP。您可以使用库(例如 smack)来避免自己实现整个协议。
XMPP 相对于 RMI 或您自制的协议的主要优点是,它是一个完全用于此目的的成熟协议:IM。
一些已经使用 XMPP 的聊天服务包括 Google Chat (GTALK) 和 Facebook。
I would use straight socket connection, using a well known protocol such as XMPP. You can use a library (like smack) to avoid implementing the whole protocol yourself.
The main advantage of XMPP over RMI or your self-made protocol is that is a well established protocol used for exactly that purpose: IM.
Some chat services already using XMPP include Google Chat (GTALK) and Facebook.
我已经使用 XMPP 协议使用 Smack API 完成了此操作。
I already did this using Smack API, using XMPP protocol.
CometD 专为聊天室等用例而设计。与其他协议不同,它通过 HTTP 端口 80 运行,这意味着(几乎)不会遇到防火墙的麻烦。
收听Greg Wilkins 最近关于该项目的播客,其中详细介绍了实施聊天室的问题以及 CometD 如何处理它。
我相信如果你需要在对话双方都有客户端(通常前端是 JavaScript),CometD 有一个 Java 客户端。
CometD has been specifically designed for use cases such as Chatrooms. Differently from other protocols, it works over HTTP port 80, which means (nearly) no hassles with Firewalls.
Listen to a recent podcast with Greg Wilkins about the project, which goes into some details of issues with implementing Chatrooms and how it gets handled by CometD.
I believe there is a Java client for CometD if you need to have client on both sides of conversation (normally frontend is JavaScript).