实时 Web 应用程序的短轮询与长轮询? [英] Short-polling vs Long-polling for real time web applications?

查看:30
本文介绍了实时 Web 应用程序的短轮询与长轮询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个实时 Web 应用程序 据我所知,最流行的选择是短轮询和长轮询.衡量一个比另一个可能有哪些优点和缺点?

I'm building a real-time web application As far as I know, the most popular choices are short-polling and long-polling. What are the advantages and disadvantages might there be for measuring one over the other?

推荐答案

  • 短轮询(也就是基于 AJAX 的计时器):

    • Short polling (a.k.a. AJAX based timer):

      优点:更简单,不消耗服务器(如果请求之间的时间很长).
      缺点:如果您需要在服务器事件立即发生时收到通知,则不好.示例(基于ItsNat)

      Pros: simpler, not server consuming (if the time between requests is long).
      Cons: bad if you need to be notified WHEN the server event happens with no delay. Example (ItsNat based)

      长轮询(即基于 XHR 的 Comet)

      Long polling (a.k.a. Comet based on XHR)

      优点:当服务器事件立即发生时,您会收到通知.缺点:更复杂,使用的服务器资源更多.示例(基于ItsNat)

      Pros: you are notified WHEN the server event happens with no delay. Cons: more complex and more server resources used. Example (ItsNat based)

      这篇关于实时 Web 应用程序的短轮询与长轮询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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