美文网首页
在线聊天技术选型

在线聊天技术选型

作者: __XY__ | 来源:发表于2018-04-13 11:44 被阅读0次

聊天技术哪家强

实现原理层面大概有以下几种
轮询,常轮询,异步,长连接,新协议。

在线聊天技术与普通cs服务的区别

普通的cs服务都是同步的,即客户端一个request一直在等待response的回答。如果采用这种同步的模型去假设在线聊天服务,只能用轮询,这样的话做了很多无用功,很多请求都是无效的。这种技术基本被pass。
与轮询比较相似的技术是常轮询(long poll) ,
聊天技术无非轮询,异步,长连接 三种模式。

[long poll] wiki

Long polling is itself not a true push; long polling is a variation of the traditional polling technique, but it allows emulating a push mechanism under circumstances where a real push is not possible, such as sites with security policies that require rejection of incoming HTTP/S Requests.

With long polling, the client requests information from the server exactly as in normal polling, but with the expectation the server may not respond immediately. If the server has no new information for the client when the poll is received, instead of sending an empty response, the server holds the request open and waits for response information to become available. Once it does have new information, the server immediately sends an HTTP/S response to the client, completing the open HTTP/S Request. Upon receipt of the server response, the client often immediately issues another server request. In this way the usual response latency (the time between when the information first becomes available and the next client request) otherwise associated with polling clients is eliminated.[10]

For example, BOSH is a popular, long-lived HTTP technique used as a long-polling alternative to a continuous TCP connection when such a connection is difficult or impossible to employ directly (e.g., in a web browser);[11] it is also an underlying technology in the XMPP, which Apple uses for its iCloud push support.

[long poll]中文

long poll并不是真的push ,是传统poll技术的一个变种,但是通过实现了一种push,用例比如需要拒绝一些request情况的站点。
客户端正常的请求就ok了,只不过你要有预期: server 不会立即返回。
server收到后不会立即返回空数据,而是保持request是开的,直到有了response。
client收到之后一般会再次发起请求
通过这种方式,消除了响应延迟(收到可用数据与发起下次请求之间的时间)

例如,BOSH是一种流行的,长期存在的HTTP技术,当这种连接很难或不可能直接使用时(例如,在Web浏览器中),它被用作连续TCP连接的替代方案; [11]也是苹果公司用于其iCloud推送支持的XMPP中的一项基础技术。

long poll 与 Poll 的区别

long poll 需要服务器和客户端配合

  • 服务器不会立即返回数据,直到有新消息
  • 客户端收到请求之后要立即再发起请求

长连接

tcp连接不会断掉,http层面即,keep alive。
这样的话优先很明显。变成模型变得很简单,缺点是服务器为了维持这些链接要耗很多资源,而且能维持的连接的个数是有限的。

异步

应用追光,性能最强的技术方式。
服务器仍然采用传统的编程模型,不过把返回数据变为异步返回。
解决了上面维持链接性能的问题,又解决了请求无效的问题。

如何实现异步

  • 关键字yield
  • async/await 模型
  • asyncio
  • aiohttp

新协议

比较有名数 websocket协议,同时还有socketio协议。
目前应用比较广的有socketio协议。

相关文章

  • 在线聊天技术选型

    聊天技术哪家强 实现原理层面大概有以下几种轮询,常轮询,异步,长连接,新协议。 在线聊天技术与普通cs服务的区别 ...

  • 开发一个在线聊天

    在线聊天技术选型 在线聊天因为涉及到互相通信,所以采用socket.io 前端框架 vue2 打包工具 vite ...

  • 爬虫(3-1 3-2)

    3-1 爬虫技术选型,爬虫能做什么?技术选型:scrapy vs requests+beautifulsoup1....

  • 技术选型指南

    这是一篇综合类技术选型指南,试图为你提供一份比较通用的技术选型思维框架。当你需要进行技术选型时,可以参照它来设计自...

  • 伴鱼数据库选型的思考,为什么我们 all in TiDB

    作者:伴鱼技术团队 技术选型是由技术方向和业务场景 trade-off 决定的,脱离业务场景来说技术选型是没有任何...

  • Metal基础入门

    一、背景和技术选型 关于技术方案的选型,最权威的肯定是Metal for OpenGL Developers[ht...

  • 引言

    写在前面 公司需要开发一款App,医疗行业,主要涉及功能模块 资讯 在线问诊 健康档案 我的 技术选型 由于公司人...

  • 通过阿里云maxcompute快速构建数据仓库

    前期技术选型 技术选型确定 鉴于开发资源,以及尚无大数据的技术基础,选用了可以快速上手的阿里云maxcompute...

  • 技术选型

    一、构建工具 gulp 任务管理,对任务文件流式操作,内存中完成,效率高 grunt 任务管理,对任务文件先读...

  • 技术选型

    介绍后台管理系统常见的组合搭配。主要是从业务逻辑层的实现和视图层考虑。 1:Angular+Bootstrap 市...

网友评论

      本文标题:在线聊天技术选型

      本文链接:https://www.haomeiwen.com/subject/ttcckftx.html