是否有真正的服务器推送通过 http? [英] Is there a real server push over http?

查看:19
本文介绍了是否有真正的服务器推送通过 http?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一些方法可以伪造它,轮询(或长轮询),但是有没有办法让服务器联系浏览器以推送信息?

I know there are ways to fake it, polling (or long polling) but is there any way to have the server contact the browser to push out information?

任何一种轮询选项都会浪费服务器上的资源,并且依赖于服务器可以将其锁定(例如 apache 和 iis).

Either polling option wastes resources on the server and depending on the server can lock it up (apache and iis for example).

似乎很多网站都在使用长轮询来伪造 http 上的服务器端推送机制.在浏览器中内置真正的推送协议不是更好吗?

Seems like a lot of sites are using long polling to fake a server-side push mechanism over http. Wouldn't it just be better to have a true push protocol built into a browser?

有哪些服务器友好的选项可以将(虚假或其他)信息推送到网络浏览器?

What options are there that are server friendly to push (fake or otherwise) information to web browsers?

推荐答案

我知道有一些方法可以伪造它,轮询(或长轮询),但是有没有办法让服务器联系浏览器以推送信息?

I know there are ways to fake it, polling (or long polling) but is there any way to have the server contact the browser to push out information?

必须首先由客户端建立到服务器的连接.服务器无法联系网络客户端.

The connection must be first established by the client to the server. There's no way of a server contacting a web client.

任何一种轮询选项都会浪费服务器上的资源,并且依赖于服务器可以将其锁定(例如 apache 和 iis).

Either polling option wastes resources on the server and depending on the server can lock it up (apache and iis for example).

没错.频繁轮询效率低下,这是我们转向具有持久连接的推送世界的原因之一.WebSockets 将是最好的解决方案.我为 Pusher 工作,这是一个托管的实时 WebSocket 解决方案,我们已经看到了由社区推动的这项技术的大量采用相信这是解决资源和实时通信问题的最佳解决方案.

That's correct. Frequent polling is inefficient which is one of the reasons we are moving to a push world with persistent connections. WebSockets will be the best solution for this. I work for Pusher, a hosted realtime WebSocket solution, and we've seen a massive uptake in this technology driven by a community that believe it's the best solution to the resource and realtime communication problem.

似乎很多网站都在使用长轮询来伪造 http 上的服务器端推送机制.在浏览器中内置真正的推送协议不是更好吗?

Seems like a lot of sites are using long polling to fake a server-side push mechanism over http. Wouldn't it just be better to have a true push protocol built into a browser?

是的,这就是我们现在拥有 WebSockets 的原因.针对 Web 浏览器的 HTTP 解决方案最终是一种黑客行为,并且在浏览器之间无法始终如一地(以相同方式)工作.

Yes, that's why we now have WebSockets. HTTP solutions to web browsers are ultimately a hack and don't work consistently (in the same way) between browsers.

有哪些服务器友好的选项可以将(虚假或其他)信息推送到网络浏览器?

What options are there that are server friendly to push (fake or otherwise) information to web browsers?

  • HTTP 长轮询:连接保持打开状态,直到服务器有新信息.注意:这与标准轮询不同,在标准轮询中,请求新信息完全是浪费时间.
  • HTTP Streaming:这可能是您正在寻找的解决方案(回答 HTTP 问题).使用这种技术,连接保持打开状态,新信息可以通过现有连接从服务器推送到客户端,而无需像使用 HTTP 长轮询那样关闭和重新打开连接.
  • HTTP/2 服务器推送:另一种从服务器推送到客户端的标准化机制.这些被称为推送响应",浏览器可能会缓存这些.
  • WebSockets:在 Web 浏览器(或任何 Web 客户端)内通过单个 TCP 连接进行全双向和全双工通信.
    • HTTP Long-Polling: The connection is held open until the server has new information. Note: this is different to standard polling where requests for new information can be a complete wast of time.
    • HTTP Streaming: This is probably the solution you are looking for (answering the HTTP question). Using this technique the connection is held open and new pieces of information can be pushed over that existing connection, from server to client, without the connection being closed and re-opened as it is with HTTP Long-Polling.
    • HTTP/2 Server Push: Another standardised mechanism for pushing from server to client. These are known as "pushed responses" and the browser may cache these.
    • WebSockets: Full bi-directional and full duplex communication over a single TCP connection within a web browser (or any web client).
    • 相关信息和资源:

      1. 您可以认为服务器发送的事件(EventSource API) 作为 HTTP 长轮询和 HTTP 流的标准化.
      2. HTTP/2 服务器推送
      1. You can think Server-Sent Events (the EventSource API) as a standardisation of of HTTP Long-Polling and HTTP-Streaming.
      2. HTTP/2 Server Push

      这篇关于是否有真正的服务器推送通过 http?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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