使用XMPP或WebSocket,为什么在用户之间进行实时通信时需要服务器? [英] using XMPP or WebSocket, why there is a server needed in real-time communication between users?

查看:136
本文介绍了使用XMPP或WebSocket,为什么在用户之间进行实时通信时需要服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在底部,所有内容都与套接字通信有关。如果有某种方式可以获取两个用户的IP,为什么不能直接在用户之间建立连接,而不必通过中间的服务器呢?



没有人强迫我们拥有基于服务器的实时通信模型。 Infact XMPP具有名为无服务器消息传递 的扩展名,该扩展名定义了如何使用以下方式在本地或广域网中进行通信:用于端点发现的零配置网络的原理以及用于实时通信的XML流和XMPP消息传递的语法。此方法使用基于DNS的服务发现和多播DNS来发现支持该协议的实体,包括其IP地址和首选端口。



P2P聊天应用程序已经使用了十年了。将服务器置于中间纯粹是取决于您的应用程序需求的决定。如果您的应用程序可以在用户在联机/脱机状态之间转换时失去聊天,那么您可以直接使用P2P模型。同样,在选择基于服务器的消息传递模型时,也有很多优点(联系人列表管理,化身,实体发现,状态授权,脱机消息等)。如果您试图在基于P2P的客户中拥有所有这些权利,则由于他们自己需要执行所有工作,他们可能会死亡或表现不佳。



WebSocket不是为P2P /无服务器通信而设计的,而是被设计为通过无状态HTTP协议提供标准化的PUSH语义。简而言之, WebSockets是一种标准化的方式,可替代黑客彗星,长轮询,分块编码,jsonp,基于iframe以及其他各种技术,这些技术开发人员已使用它们来模拟通过HTTP进行服务器推送。


At the bottom, it's all about socket communications. If there is some way to get the ip of the both users, why can't the connection be directly setup between the users instead of having to go thru a server in the middle?

解决方案

My 2 cents:

No one out there forces us to have a server based real-time communication model. Infact XMPP have an extension called "Serverless Messaging" which defines how to communicate over local or wide-area networks using the principles of zero-configuration networking for endpoint discovery and the syntax of XML streams and XMPP messaging for real-time communication. This method uses DNS-based Service Discovery and Multicast DNS to discover entities that support the protocol, including their IP addresses and preferred ports.

P2P chat applications have been for over a decade now. Having a server in the middle is purely a decision dependent upon your application needs. If your application can live with chats getting lost while the user was transitioning between online/offline status, then you can very well have a direct P2P model going. Similarly, there are a loads and loads of advantages (contact list management, avatars, entity discovery, presence authorization, offline messages, ....) when it comes to choosing a server based messaging model. If you try to have all this right inside your P2P based clients, they might die or under-perform because of all the work they will need to perform by themselves.

"WebSockets" were not designed for P2P/Serverless communication, rather they were designed to provide a standardized PUSH semantic over stateless HTTP protocol. In short, "WebSockets" is a standardized way replacing hacky comet, long-polling, chunked-encoding, jsonp, iframe-based and various other technique developers have been using to simulate server push over HTTP.

这篇关于使用XMPP或WebSocket,为什么在用户之间进行实时通信时需要服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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