无轮询且无插件的持久连接示例

发布于 2024-12-23 06:01:25 字数 452 浏览 4 评论 0原文

我发现一个有趣的库,允许从服务器进行 DOM 操作,这允许对浏览器隐藏大部分逻辑,因此,浏览器看到的只是您选中该框时发生的情况,它实际上并不知道您选中该框时要做什么。

看到它响应如此之快,我查看了网络活动,发现了一个带有HTTP 101(切换协议),它表示连接仍然​​打开。

JavaScript 中似乎有一种方法可以接收流数据

怎么会这样呢?该代码有点大,我所做的谷歌搜索表明它将被称为 Comet,但是有更多关于高度跨浏览器的“长轮询”的信息,但这似乎并不是正在发生的事情。

如何快速获得这样的结果的(简单)示例是什么?

I found an interesting library that allows DOM manipulation from the server, this allows much of the logic to be hidden from the browser, so all the browser gets to see is what happens when you check the box, it does not actually know what to do when you check the box.

Seeing that it responds so quickly, I took a look at the network activity, and found an item with HTTP 101 (switching protocols) and it says the connection is still open.

It seems there is a way in JavaScript to receive streaming data.

How can this be? The code is somewhat large and the googling I did indicated it would be called Comet, but there is much more information about the highly cross-browser "long polling", but that does not seem to be what is happening.

What is a (simple) example for how to achieve fast results like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一刻暧昧 2024-12-30 06:01:25

HTTP/1.1 101响应头是Websocket协议握手。

我发现 socket.io 是最好的现成滚动库(客户端和服务器),尤其是在使用 JavaScript 时。如果可能的话,Socket.io 将放弃使用 flash 套接字,然后在不支持 Websockets 的旧浏览器中使用长轮询作为最后手段。

The HTTP/1.1 101 response header is the Websocket protocol handshake.

I have found socket.io to be the best ready rolled library (both client and server), especially when working with JavaScript. Socket.io will drop to flash sockets if possible then last resort long polling in older browsers that do not support Websockets.

七色彩虹 2024-12-30 06:01:25

长轮询是一种推送技术。在 Web 套接字(HTML 5)之前,Web 遭受类客户端服务器问题。在客户端请求之前,服务器无法推送。因此无法将数据推送给客户端。长轮询是实现这一目标的方法之一。

它以简单的方式工作。客户端向服务器发出请求,服务器如果有任何新内容,将立即提供服务或等待新内容到来。当有新内容出现时,服务器会发送响应。收到响应后,客户端将再次向服务器重新发出请求。还有其他实现推送技术的方法。阅读此内容:wiki

Long Polling is a push technology. Before web sockets(HTML 5), the web suffered from class client server problem. The server can not push until client requests. So it was not possible to push data to clients. Long Polling is one of the way to do it.

It works in the simple way. The client would make a request to server, the server if has anything new to server would serve immediately or would wait till new content comes. When ever a new content comes, the server would send the response. On receiving the response, the client would again re-issue a request to the server. There are other ways of implementing Push Technology. Read this : wiki

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文