114

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?
Khafaga
  • 1,537
  • 4
  • 15
  • 24
  • 1
    I recently stumbled across the same issue, my answer was to go for WebSockets. Node.JS is getting to be an extremely popular language, and by rights it should be. XMPP is ok - however in my opinion you are limiting yourself moving forward by deciding to go for this older technology. Node is however a tricky beast and you have to approach it differently to how you would JavaScript. If you are patient enough I would suggest going Node - not just for this, but it will allow you to expand in other areas with more ease. – JustSteveKing Oct 24 '14 at 13:43
  • 7
    XMPP is an Extensible Messaging and Presence Protocol, Websocket is a protocol that provides full duplex communications over Port 80. You compare Apples to Oranges. – Flow Oct 24 '14 at 14:34
  • 21
    @Flow: I'm might be comparing apples to oranges in your opinion. But what I'm asking is which I should choose when developing a website that provide a real time chat capability. – Khafaga Oct 25 '14 at 00:00
  • 1
    @JustSteveKing Most things are already done in XMPP however you have to manage those things in node.js. This is equal to reinventing the wheel again. – Shahid Karimi Jul 30 '15 at 09:16

1 Answers1

164

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

Kev
  • 2,234
  • 1
  • 12
  • 6
  • 1
    Hi sorry, the questions has been a while, i am just wondering, so does it mean transporting binding is like socket.io/strophe.js, and the xmpp is like (openfire/Ejabbered)? – John Aug 20 '15 at 06:09
  • 1
    No, what you're naming there are libraries versus servers. – Kev Jul 22 '16 at 10:39
  • Here's more about layers (incl. transport, application layers): https://en.wikipedia.org/wiki/OSI_model – Karina Klinkevičiūtė Aug 17 '16 at 10:58
  • 3
    good answer from Kev but it may worth pointing out 1>TCP belongs to layer 4 - transport layer while both HTTP and Websocket belong to layer 7 - application layer. – RoundPi May 01 '20 at 09:31
  • Indeed @Gob00st - I'm confused here as well. This answer from Kev says "both" because _"you'd use websockets (in a modern browser) ...as the **network transport**"_. But how do we reconcile that with the fact that WebSocket (as XMPP and HTTP) are actually **application** (**not** transport) protocols in i.e. OSI layer 7? Why would XMPP go "on top of" WebSockets in a modern browser? – Amelio Vazquez-Reina Jun 25 '20 at 17:48
  • but wikipedia says both xmpp and websockets are application layer protocols.I did not understand how can we use websockets on top of xmpp here? – rahul sharma Dec 27 '20 at 15:45
  • 1
    You don't use websockets on top of XMPP, you use XMPP on top of websockets. Websockets may be an application layer protocol in the OSI model, but that's not particularly helpful when you're talking about layering more protocols on top of websockets. It is much easier to think of websockets as being a network transport for XMPP, when using them with XMPP. – Kev Jan 22 '21 at 17:41