Xmpp Vs Websocket

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.

  1. What was the need for websocket if xmpp was good in handling real time conversations?
  2. What are the major differences between the 2 protocols?
  3. And when should I choose one of them over the other?
36195 次浏览

简短的回答是“两者都有”。

XMPP 是一组用于实时聊天(以及其他许多事情)的应用程序协议——它必须以某种方式通过网络传输,因此需要传输绑定。XMPP-有三种主要的传输绑定

  1. TCP/IP,这是人们通常在因特网上与设备上的本机客户端一起使用的
  2. HTTP (称为 BOSH) ,这是人们在浏览器中使用 XMPP 时的传统使用方式(因为浏览器中的 Javascript 应用程序无法使用 TCP-IP)
  3. Websockets,这是在现代浏览器中进行 XMPP 时使用的一种工具。

因此,如果您在浏览器中开发聊天应用程序,您可以选择 XMPP 作为应用程序协议,并使用 websockets (在现代浏览器中)或 BOSH (在较老的浏览器中)作为网络传输。如果你使用像 Stanza.io (https://github.com/otalk/stanza.io)这样的 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.)