Comet是如何实现的?
我想知道如果请求的连接还没有完成,客户端如何得到响应?
原理是什么?
事实上,我已经阅读了很多关于这个主题的帖子:
How do I Implement basic“Long Polling” "?
但都没有解决我的疑问
I wander how do client side get response if the connection of request is not finished yet?
What's the principle?
In fact I've read quite a few posts on this subject:
How do I implement basic "Long Polling"?
How does the live, real-time typing work in Google Wave?
But none of them solve my doubt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案取决于所使用的技术。
使用“隐藏 Iframe”技术的 HTTP 流可以做到这一点。该技术是服务器将
元素发送到隐藏的 iframe。每个脚本元素将包含一些可执行的 JavaScript。该技术依赖于这样一个事实:浏览器通常在加载 HTML 元素后立即对其进行解释。这样,客户端就不需要任何类型的轮询代码;脚本标签将包含适当的函数调用,并且浏览器将在脚本元素完全加载后立即执行这些调用。
The answer depends on the technique used.
HTTP streaming, using the "hidden Iframe" technique, can do this. The technique is that the server sends
<script>
elements to the hidden iframe. Each script element will contain some executable JavaScript. This technique relies on the fact that browsers generally interpret an HTML element as soon as it is loaded. In this way, there is no need for any sort of polling code in the client; the script tags will contain the appropriate function calls, and the browser will execute those calls as soon as the script element is completely loaded.