Xmpp与Websocket [英] Xmpp Vs Websocket

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

问题描述

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

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. 如果xmpp在处理实时对话方面表现良好,对websocket的需求是什么?

  2. 两种协议之间的主要区别是什么?

  3. 我应该何时选择其中一个?


推荐答案

简短的回答是'both'。

The short answer is 'both'.

XMPP是一套用于进行实时聊天的应用程序协议(以及许多其他内容,用于实现然而,它必须以某种方式通过网络传输,因此您需要传输绑定。 XMPP有三种主要的传输绑定 -

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,这是人们通常在Internet上使用设备上的本机客户端

  2. HTTP(称为BOSH),这是传统上在浏览器中使用XMPP时使用的(因为浏览器中的Javascript应用程序无法使用TCP-IP)

  3. Websockets,它是在现代浏览器中执行XMPP时使用的。

因此,如果您正在开发在浏览器中使用聊天应用程序,您可以选择XMPP作为应用程序协议,并使用websockets(在现代浏览器中)或BOSH(在旧浏览器中)作为网络传输。如果你使用像Stanza.io这样的Javascript的XMPP库( https://github.com/otalk/stanza。 io ),它将支持两者,你只需要考虑'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.

(您不能使用'just websockets'进行聊天 - 您可以使用没有XMPP的websockets,但这实际上意味着您正在发明自己的应用程序层协议进行聊天,并且你可能会利用已经用于编写具有有用属性(安全性,身份,可扩展性等)的工作来节省大量时间和麻烦,并且现有的库和服务器由改为使用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.)

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

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