Xmpp Vs Websocket [closed]

我只是一个虾纸丫 提交于 2019-11-28 15:31:02

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 -

  1. TCP/IP, which is what one usually uses on the Internet with native clients on devices
  2. 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)
  3. Websockets, which is one one uses when doing XMPP in a modern browser.

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.

(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.)

Basically, you are comparing two different things to each other. XMPP is an application protocol while WebSockets is a transport protocol.

I think using XMPP will save you a lot of time. However, you will lose the freedom to implement functionalities the way that suites you best. If your application will use only One-to-one messaging and friend list functions with no clear plan on what you would add in the future, WebSockets + would be a viable solution. On the other hand, if your application will benefit from other XMPP extensions such as Multi-party messaging and Peer-to-peer media sessions it would be better to use XMPP as such functions will require a lot of time to be implemented.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!