0

What is the best way to push data to a client in real time? I am working on a test website with the new html5 history API when I ran into this conundrum.

I am using the twitter API to make real time search for learning purposes, but

So I understand that you could essentially submit a form over and over again, spamming PHP endlessly, but that doesn't seem like a good solution.

What is the best way to get data as data is created? (with jQuery, preferably)

Thanks, David

Edit: I've looked into push engines, but there's got to be a way to do it without buying a service, right?

4

1 回答 1

1

我看到了两种可能的解决方案(如果您包含像 flash 之类的浏览器插件,实际上还不止这些):websockets 和轮询。你不喜欢投票的想法,我会同意,这取决于场景。轮询的缺点是保持用户会话处于活动状态——即他们永远不会被注销——如果轮询同一个域的话。但是,如果您将其设置为每 5 秒轮询一次,假设您将其设置为检查新数据,负载将非常小。使用 jQuery,您可以实现一个 setInterval 来轮询(我相信您已经调查过)。另一方面,WCF 引入了一种基于 HTTP 的类似 TCP 套接字的连接,称为轮询双工,它允许客户端和服务器像通过 TCP 连接一样进行通信。你可以查看这些的表现 - 它' 如果您想以某种方式实现它,那还不错。我使用 Silverlight 来实现这一点。Websockets 是一种相对较新的技术,可为您提供双向通信,但您将客户端限制为使用支持这些的浏览器的客户端。您还必须处理特定于浏览器的问题。

于 2013-04-30T15:33:41.887 回答