Xmpp 与 Websocket [英] Xmpp Vs Websocket

查看:27
本文介绍了Xmpp 与 Websocket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我即将开发一个具有近乎实时聊天功能的网站.我知道它可以使用 xmpp 或 websocket 协议来实现.我也知道xmpp协议是1999年开发的,我想现在应该已经成熟了.另一方面,websocket协议是2011年开发的.

  1. 如果 xmpp 擅长处理实时对话,还需要什么 websocket?
  2. 这两种协议之间的主要区别是什么?
  3. 我什么时候应该选择其中之一而不是另一个?

解决方案

简短的回答是两者".

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

  1. TCP/IP,这是人们通常在 Internet 上与设备上的本机客户端一起使用的内容
  2. HTTP(称为 BOSH),这是在浏览器中使用 XMPP 时传统上使用的(因为 TCP-IP 不适用于浏览器中的 Javascript 应用程序)
  3. Websockets,这是在现代浏览器中执行 XMPP 时使用的一种.

因此,如果您在浏览器中开发聊天应用程序,您会选择 XMPP 作为应用程序协议,并使用 websockets(在现代浏览器中)或 BOSH(在旧浏览器中)作为网络传输.如果您将 XMPP 库用于 Javascript,例如 Stanza.io (https://github.com/otalk/stanza.io),它将同时支持两者,并且您只需要考虑XMPP"而不是传输层,而不是在设置时必须告诉它要连接到哪个端点.

(你不能只使用 websockets 进行聊天——你可以在没有 XMPP 的情况下使用 websockets,但这真正意味着你正在发明你自己的聊天应用层协议,而且很可能你是将通过利用已经开始编写具有有用属性(安全性、身份、可扩展性等)的工作来节省大量时间和麻烦,并且通过使用 XMPP 来替代现有的库和服务器.)

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?

解决方案

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

这篇关于Xmpp 与 Websocket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆