Ajax 聊天轮询带宽效率

Ajax chat polling bandwidth efficiency(Ajax 聊天轮询带宽效率)
本文介绍了Ajax 聊天轮询带宽效率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个小型 Web 应用程序,它基本上是浏览器中的一个 JQuery 支持的聊天客户端,为了获取我正在使用 AJAX 请求轮询服务器然后附加任何新回复的帖子,我很担心这在不失去实时感的同时尽可能高效.

I've written a small web application which is basically a JQuery powered chat client within the browser, to get the posts I'm polling the server with an AJAX request and then appending any new replies, I'm worried about making this as efficient as possible while not losing the realtime feel.

http://darklightweb.co.uk/RealTime/

我看不到任何可能发生中断的方式,因此我每 5 秒轮询一次页面,如果没有可用的新帖子以保持数据传输处于空闲状态,则该页面不返回任何内容,如果它确实有消息顶部队列中的消息被发送出去,我会在 Ajax 请求完成后再次检查,直到消息队列为空.

I can't see any way that interrupts are possible so I am polling a page every 5 seconds that returns nothing if no new posts are available to keep data-transfer down if it's idle, if it does have a message the top message in the queue is sent out and I'm checking again as soon as the Ajax request has finished until the message queue is empty.

关于使这个尽可能低带宽或可能的替代实现的任何其他提示?

Any other tips on making this as low-bandwidth as possible or possible alternate implementations?

推荐答案

轮询可能不是实现聊天的最佳解决方案 - 我建议看看 JQuery 的实现 COMET 保持与客户端的开放连接并从服务器关闭"推送更新,并且也是 相当可扩展.

Polling might not be the best solution for implementing a chat - I'd suggest taking a look at JQuery's implementation of COMET which keeps an open connection to the client and pushes updates from the server 'down' and is also quite scalable.

这篇关于Ajax 聊天轮询带宽效率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to trim() white spaces from a string?(如何从字符串中去掉()空格?)
price depend on selection of radio input(价格取决于无线电输入的选择)
calculate price depend on selection without button(根据没有按钮的选择计算价格)
How to minify json response?(如何缩小JSON反应?)
Laravel 5.3 with Vuejs ajax call尝试使用 Vuejs 从数据库中获取一些数据。我的用户表中有一些虚拟数据。我想在我的视野中展示它们。问题是虽然页面加载,但...
Passing Data between react components(在Reaction组件之间传递数据)