在网站中设计一个聊天客户端。我应该使用 XMPP 吗?
我将使用 ruby on Rails 设计一个网站。我想要实现的功能之一是聊天功能。用户可以与网站的其他用户/成员聊天。我应该使用什么或者换句话说开始学习什么才能设计类似的东西?
XMPP 就是答案吗?如果是这样,如果有人能对从那里去哪里进行一些描述和/或推荐一些书籍,我会很高兴。谢谢 !
我说 XMPP 是因为我知道 Facebook 使用它并且我计划创建类似的东西
I am going to design a website using ruby on rails. And one of the features i want to implement is the chat functionality. Where users can chat with the other users/members of the website. What i should be using or in other words start learning in order to design something like that ?
Is XMPP the answer. if so, i would be glad if someone could be a bit descriptive on where to go from there and/or suggest some books. thanks !
I said XMPP because i know Facebook uses that and i plan to create something similar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
协议可能会成为一个非常棘手的话题,如果没有经验,自己实现一个运行良好的协议可能会非常令人畏惧。特别是当它与多方之间的(近)实时通信有关时。如果要扩展到任何大量的访问者,正确实施这一点可能会非常困难。
XMPP 是一个已经很成熟的协议,经过了一些调整,并且已经有许多稳定的实现。因此在使用它时,您无需再担心协议的设计或实现。出于这个原因,我真的会推荐它。它也是一个相当容易理解的协议,即使您在一开始必须花一些时间阅读基础知识。进一步查找 http://xmpp.org 文档。
设置 XMPP 服务器只需几分钟即可完成,具体取决于您的操作系统和您选择的服务器。需要注意的是,如果您想要自定义服务器,您还必须在某种程度上了解它的内部结构,这可能需要也可能不需要一些时间。
底线是:选择 XMPP 以及现有的 XMPP 库和服务器,您可以免费获得 90% 的功能,并且可以专注于实现您的客户端。问题是,您需要深入研究 XMPP 和服务器的细节多少,这会比滚动您自己的协议花费更长的时间吗?从长远来看,您自己的协议是否能像 XMPP 一样满足您的需求?
Protocols can become a pretty hairy topic, implementing a well-working protocol yourself can be pretty daunting without prior experience. Especially if it has to do with (near) real-time communication between several parties. If this is supposed to scale to any significant number of visitors, implementing this correctly can be pretty tough.
XMPP is a protocol that is already well established, is shaken down and already has many stable implementations. So when using it, you do not need to worry about designing or implementing the protocol anymore. For that reason, I'd really recommend it. It's also a rather easy to understand protocol, even if you will have to spend some time reading up on the basics in the beginning. Look neigh further than http://xmpp.org for documentation.
Setting up an XMPP server can be done in minutes, depending on your OS and the server you choose. The caveat is that if you want to customize the server at all, you will have to learn about the innards of it as well to some degree, which may or may not take some time.
The bottom line is: choosing XMPP and existing XMPP libraries and servers, you get 90% of the functionality for free and can concentrate on implementing your client. The question is, how much will you have to dig into the details of XMPP and the server, will this take longer than rolling your own protocol and will your own protocol suit your needs in the long term as well as XMPP would?
您始终必须考虑要花多少钱来实现这一点。
如果您使用 XMPP,您将能够运行 XMPP 标准聊天服务器(在 Rails 之外),并且应该能够使用带有 XMPP 到 HTTP 桥接器的 JavaScript 客户端。
Google 快速搜索提出的一个项目是 Strope。
但我认为,您应该仔细考虑 XMPP 是否真的适合您的需求以及您是否真的想经历所有这些麻烦来进行聊天。
实现您自己的也并不简单,尤其是当您自己编写所有长轮询和信号发送内容时。
但这并非不可能,并且应该会在几天内为您提供一个简单的工作解决方案。
然而,在 Rails 中自己进行聊天将需要您使用替代数据库,因为 Rails 无法在请求之间将数据存储在内存中,并且在 ActiveRecord 中保留聊天数据似乎不是一个可扩展性很好的好主意。
使用 XMPP 显然有一个好处,即您的用户能够使用 iChat、Jabber 或任何其他 XMPP 客户端连接到您的聊天服务。
You always have to think about how much you want to spend on implementing this.
If you go with XMPP you will be able to run a XMPP standard chat server (outside of Rails) and should be able to use a JavaScript Client with a XMPP to HTTP Bridge.
A project a quick Google Search brought up doing this is Strophe.
But I'd argue that you should think long and hard about if XMPP really suits your needs and if you really want to go through all that trouble for a Chat.
Implementing your own is also not straightforward, especially when you are writing all the long-polling and signaling stuff yourself.
But it's not impossible and should give you a simple working solution in a couple of days.
Doing the chat yourself in Rails will require you however to use an alternative Database since Rails can't store data in-memory between requests and persisting chat data in ActiveRecord seems like not a very scalable and good idea.
Using XMPP obviously has the benefit of your users being able to connect to your Chat service using iChat, Jabber or any other XMPP Client..