简体   繁体   English

当 websocket 已经可用时,是否有理由需要 HTTP2?

[英]Is there a reason why HTTP2 is required when websocket is already available?

Is there a reason why HTTP2 is required when websocket is already available?当 websocket 已经可用时,是否有理由需要 HTTP2?

Nathan Aw (Singapore) Nathan Aw(新加坡)

Why do we need HTTP/2 when we have WebSockets?当我们有 WebSockets 时,为什么我们需要 HTTP/2? Well why did we need WebSockets when we have TCP?那么当我们有 TCP 时,为什么我们需要 WebSockets? Or even IP?甚至IP? Protocols are basically agreed standards that can be implemented by independent parties.协议基本上是可以由独立各方实施的商定标准。

WebSockets are good for two way communication but are mostly unstructured on top of that and application specific. WebSockets 适用于双向通信,但主要是非结构化的,并且是特定于应用程序的。 HTTP is (mostly) a series of one-way requests to the server (ask for a resource, receive an answer) — though HTTP/2 enhances that slightly with HTTP/2 push and the binary framing layer could in theory be used more for proper two way push. HTTP(主要)是对服务器的一系列单向请求(请求资源,接收答案)——尽管 HTTP/2 通过 HTTP/2 推送稍微增强了这一点,并且二进制帧层理论上可以更多地用于正确的双向推动。 So the full two way nature of WebSockets — the very thing they are good at — is not really needed for most HTTP use cases.因此,对于大多数 HTTP 用例来说,WebSockets 的完整双向性质——它们所擅长的东西——并不是真正需要的。

Looking at HTTP, it has various extras that WebSockets does not have.看看 HTTP,它有各种 WebSockets 没有的额外功能。 Including defined methods, headers and compression.包括定义的方法、标头和压缩。 This allows a well-defined understanding between various HTTP implementations to facilitate communications for its use case including features like multiplexing , caching, compression, redirects, error handling... etc. If you had to reinvent all of those on top of WebSockets (which is a very raw protocol), you'd end up with an HTTP/2 like protocol.这允许在各种 HTTP 实现之间有明确定义的理解,以促进其用例的通信,包括多路复用、缓存、压缩、重定向、错误处理等功能。是一个非常原始的协议),你最终会得到一个类似 HTTP/2 的协议。

Could HTTP/2 have used WebSockets to act as it's underlying transport layer? HTTP/2 可以使用 WebSockets 作为它的底层传输层吗? Possibly, but that's an unnecessary extra level of abstraction (IP->TCP->WS->HTTP2->HTTP), not to mention that websockets are often established over HTTP initially.可能,但这是一个不必要的额外抽象级别(IP->TCP->WS->HTTP2->HTTP),更不用说 websockets 通常最初是通过 HTTP 建立的。 HTTP is big enough to have its own transport protocol so in fact they've gone the other way and specified WebSockets over HTTP/2 . HTTP 足够大,可以拥有自己的传输协议,因此实际上他们已经走了另一条路,并通过 HTTP/2 指定了 WebSockets

Finally, it should also be noted that HTTP/2 does not make Web Sockets obselete either.最后,还应该注意的是, HTTP/2 也不会使 Web Sockets 过时 They are different and with different advantages and disadvantages.它们是不同的,具有不同的优点和缺点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么需要websocket sendMessage - Why websocket sendMessage is required Websocket,Server Sent Events(SSE)和HTTP2的Server Pushing之间有什么区别? - What is the difference between Websocket,Server Sent Events (SSE) and HTTP2's Server Pushing? HTTP2-如何具有类似WebSocket的功能(Keep-Alive,EventSource等) - HTTP2 - How to have WebSocket-like functionality (Keep-Alive, EventSource, etc.) 使用websocket时发生“ TypeError:需要浮点数” - “TypeError: a float is required” occurred when using websocket 向 websocket 发送消息时地址已被使用 - Address already in use when sending message to websocket HTML5 Websocket HTTP 身份验证失败; 没有可用的有效凭据 - HTML5 Websocket HTTP Authentication failed; no valid credentials available 是什么原因导致甚至没有看到一些“有用的”和公开的基于websocket的服务? - What's the reason for not seeing even a handful of “useful” and publicly available websocket based services out there? 使用websocket和http时的nginx配置? - nginx configuration when using websocket and http? 为什么在Spring Cloud Stream App Starters项目中没有websocket源? - Why there is no websocket source available in Spring cloud stream app starters project? 在spring中使用websocket时出错“忽略消息,没有可用的主体信息” - Error “Ignoring message, no principal info available” when using websocket in spring
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM