如何显示像Facebook股票,meetup.com主页确实连续实时更新? [英] How to show continuous real time updates like facebook ticker, meetup.com home page does?

查看:194
本文介绍了如何显示像Facebook股票,meetup.com主页确实连续实时更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示在浏览器中不断实时更新,如Facebook股票,meetup.com主页呢?在Python,PHP,Node.js的,什么是服务器端的性能影响?
此外,我们如何能达到同样的事情的更新如果页面是由一个CDN像Akamai的缓存?

How to show continuous real time updates in browser like facebook ticker, meetup.com home page does? In python, PHP, node.js and what would be the performance impact at the server side ? Also how could we achieve the same update thing if the page is cached by an CDN like akamai?

推荐答案

您有两个选项(即其他人上面详细)。如果你不熟悉的一些背后的每一个选项概念性的想法,我想我给一两行他们。请注意,我是$ P $在一个非常,非常高的水平psenting这些概念。

You have two options (that others have detailed above). In case you are not familiar with some of the conceptual ideas behind each option, I figured I'd give a line or two about them. Note that I'm presenting these concepts at a very, very high-level.

您有三个选项:


  1. 短轮询

  2. 网络插座

  3. 彗星/长轮询

短轮询迫使客户不断发送请求到形式的服务器克服了客户端 - 服务器之间的单向通信:

Short Polling

Short Polling overcomes the one-way communication between Client-Server by forcing the client to continuously send requests to the server of the form:

Client: Do you have a message for me?
Server: No.
Client: (wait x seconds)
Client: Do you have a message for me?
Server: No.
Client: (wait x seconds)
Client: Do you have a message for me?
Server: Yes. Here it is!
Client: Yay!
Client: (update message)

代表客户的不断唠叨叫做查询即可。为了实现这种结构,就需要设置您的服务器听到来自客户端这些轮询请求。该服务器还必须在某处存储这些信息,所以,当消息准备就绪,服务器可以救他们。在一个非常高的一个简单的层面,你的服务器需要:

The constant nagging on behalf of the Client is called Polling. In order to implement this structure, you'll need to set up your server to "listen" to these polling requests from the client. The server will also have to store those messages somewhere, so that when messages are ready, the server can deliver them. At a very high a simplistic level, your server needs to:


  • 接受一般的网页请求

  • 接受轮询请求

  • 是获取信息运行后台作业

  • 某处存储这些信息,这样,当轮询请求进来,服务器可以检查它们。

您还需要这些轮询请求配合某种会话ID的用户,让正确的信息到达合适的人。总体而言,范式和复杂,在我看来,没有效率。

You will also need to tie these polling requests to some kind of session ID for the user, so that the right messages reach the right person. Overall, the paradigm is complicated and, in my opinion, inefficient.

网络套接字是新的HTML5。他们背后的基本想法是,客户可以维持到服务器直接连接,他们可以的的信息来回对​​方。因此,而不是通常的:客户端发送GET请求>>服务器与内容进行响应,网络套接字让你保持一个持续的对话。

Web Sockets are new to HTML5. The basic idea behind them is that the Client can maintain a direct connection to the server and they can push information back and forth to each other. Therefore, instead of the usual: Clients sends GET request >> Server responds with content, Web Sockets allow you to maintain a continuous dialogue.

为了对此进行设置,但是,你需要:

In order to set this up, however, you need:


  • 浏览器是兼容的WebSocket(不是所有的都)。

  • ,可以处理网络套接字服务器(不知道如何表达这一点,但不是所有的服务器都设置了这样的安排)。

的设置有些复杂,虽然比长轮询简单:

The setup is somewhat complicated, albeit simpler than long polling:


  • 客户端保持连接到基于Web的插座连接到服务器

  • 服务器通过网络插座结果给客户

  • 根据结果​​
  • 客户端更新页

  • Client maintains connection to Web-Socket-enabled connection to Server
  • Server pushes results to Client through web socket
  • Client updates page according to results

您会看到被称为这个模式的推送通知作为服务器已被授权(当然,如果你拥有一部iPhone,你已经经历了这一点)的的东西到客户端(如何不礼貌!)。由于有大量的客户端和服务器的细微差别,我会建议测试出如,这基本上是一个Web服务来处理所有的硬部件的东西了Web套接字。它会为你测试和着手对自己在使用前,用模式玩一个简单的方法。它拥有客户端和服务器端库。

You'll see this pattern referred to as Push Notifications (certainly, if you own an iPhone you've experienced this) as the Server has been empowered to push "stuff" to the client (how impolite!). As there are lots of client and server nuances, I would recommend testing out something like Pusher, which is basically a web service to handle all the hard parts of Web Sockets. It'll be an easy way for you to test and play with the pattern before embarking on setting it up yourself. It has both client and server-side libraries.

希望这些信息给你一个基准来解决问题。其他答案对如何解决每个方案更直接的信息。

Hope that information gives you a baseline to solve your problem. The other answers have more direct information on how to solve each scenario.

这是另一种,看似跨浏览器的方法来网络套接字是长轮询(见彗星)。在这种情况下,您的客户机建立与服务器的连接并让它挂,等待数据推后。此安装程序是有些复杂,但它并重新present 短轮询网络套接字之间的中间地带

An alternative, seemingly cross-browser approach to Web Sockets is Long-Polling (see Comet). In this case, your client establishes a connection to the server and leaves it hanging, waiting for data to be pushed back. The setup for this is somewhat complicated, but it does represent a middle ground between Short Polling and Web Sockets.

这篇关于如何显示像Facebook股票,meetup.com主页确实连续实时更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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