我编写了一个小型 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 聊天轮询带宽效率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!