Java Xmpp 与 Websocket
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26549010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xmpp Vs Websocket
提问by Khafaga
I'm about to develop a website that has near real time chat. I know that it can be implemented using xmpp or websocket protocols. I know also that the xmpp protocol has been developed in 1999 , and I guess it should be mature nowadays .On the other hand , the websocket protocol has been developed in 2011.
我即将开发一个具有近乎实时聊天功能的网站。我知道它可以使用 xmpp 或 websocket 协议来实现。我也知道xmpp协议是1999年开发的,现在估计应该已经成熟了。另一方面websocket协议是2011年开发的。
- What was the need for websocket if xmpp was good in handling real time conversations?
- What are the major differences between the 2 protocols?
- And when should I choose one of them over the other?
- 如果 xmpp 擅长处理实时对话,那么对 websocket 的需求是什么?
- 这两种协议之间的主要区别是什么?
- 我什么时候应该选择其中之一而不是另一个?
采纳答案by Kev
The short answer is 'both'.
简短的回答是“两者”。
XMPP is a set of application protocol for doing real-time chat (and many other things, for that matter) - it then has to be transported across the network somehow, so you need a transport binding. There are three main transport bindings for XMPP -
XMPP 是一组用于进行实时聊天(以及许多其他事情,就此而言)的应用程序协议 - 然后它必须以某种方式通过网络传输,因此您需要传输绑定。XMPP 有三个主要的传输绑定 -
- TCP/IP, which is what one usually uses on the Internet with native clients on devices
- HTTP (called BOSH), which is what one has traditionally used when using XMPP in the browser (as TCP-IP isn't available to Javascript apps in the browser)
- Websockets, which is one one uses when doing XMPP in a modern browser.
- TCP/IP,这是一种通常在 Internet 上与设备上的本地客户端一起使用的协议
- HTTP(称为 BOSH),这是在浏览器中使用 XMPP 时传统上使用的(因为 TCP-IP 不适用于浏览器中的 Javascript 应用程序)
- Websockets,这是在现代浏览器中执行 XMPP 时使用的一种。
So if you're developing a chat application in a browser, you'd choose XMPP as the application protocol and you'd use websockets (in a modern browser) or BOSH (in an older browser) as the network transport. If you use an XMPP library for Javascript like Stanza.io (https://github.com/otalk/stanza.io), it'll support both and you'll just be thinking about 'XMPP' rather than the transport layer, other than at setup when you have to tell it what endpoint to connect to.
因此,如果您在浏览器中开发聊天应用程序,您会选择 XMPP 作为应用程序协议,并使用 websockets(在现代浏览器中)或 BOSH(在旧浏览器中)作为网络传输。如果您使用像 Stanza.io ( https://github.com/otalk/stanza.io)这样的 JavaScript 的 XMPP 库,它会同时支持两者,您只会考虑“XMPP”而不是传输层,除了在设置时您必须告诉它要连接到哪个端点。
(You can't use 'just websockets' for chat - you can use websockets without XMPP, but what this really means is that you're inventing your own application-layer protocol for chat, and the odds are you're going to save a lot of time and headaches by taking advantage of the work that's already gone into writing one with useful properties (security, identity, extensibility etc.) and for which there are existing libraries and servers by going XMPP instead.)
(您不能使用'仅使用 websockets' 进行聊天 - 您可以在没有 XMPP 的情况下使用 websockets,但这真正意味着您正在发明自己的应用程序层协议进行聊天,并且您很有可能会节省大量的时间和头疼的工作已经通过使用 XMPP 来编写一个有用的属性(安全性、身份、可扩展性等),并且有现有的库和服务器。)