http - websockets 如何比简单的 HTTP 请求更快?

标签 http websocket comet

您仍然需要从您的计算机向网站的服务器来回发送请求。 websockets 如何让它变得更快?

最佳答案

WebSocket 是 HTTP 的扩展。对于低延迟通信,Web 套接字更好。

同时检查这个 article

How can websockets make it so much faster?

要建立 WebSocket 连接,客户端和服务器在初始握手期间从 HTTP 协议(protocol)升级到 WebSocket 协议(protocol),如下例所示:-

GET /text HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: www.websocket.org

HTTP/1.1 101 WebSocket Protocol Handshake
Upgrade: WebSocket
Connection: Upgrade
…

一旦建立,WebSocket 数据帧就可以在客户端和服务器之间以全双工模式来回发送。文本帧和二进制帧都可以全双工方式同时在任一方向发送。数据被最低限度地构造为只有两个字节。对于文本帧,每个帧都以 0x00 字节开始,以 0xFF 字节结束,中间包含 UTF-8 数据。 WebSocket 文本框架使用终止符,而二进制框架使用长度前缀。

Web Sockets represents the next evolution of web communications—a full-duplex, bidirectional communications channel that operates through a single socket over the Web. HTML5 Web Sockets provides a true standard that you can use to build scalable, real-time web applications. In addition, since it provides a socket that is native to the browser, it eliminates many of the problems Comet solutions are prone to. Web Sockets removes the overhead and dramatically reduces complexity.

延迟比较:-

enter image description here

Summary:-

Web Sockets provides an enormous step forward in the scalability of the real-time web. As you have seen in this article, HTML5 Web Sockets can provide a 500:1 or—depending on the size of the HTTP headers—even a 1000:1 reduction in unnecessary HTTP header traffic and 3:1 reduction in latency. That is not just an incremental improvement; that is a revolutionary jump—a quantum leap!

关于http - websockets 如何比简单的 HTTP 请求更快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19169427/

相关文章:

c++ - 有人能给我一个支持代理的非托管 C++ HTML 客户端的例子吗?

python - 在 Python 中将数据发布到 api 时无法将 str 连接到字节错误

java - 如何在 JavaFX 8 上禁用按钮事件直到 http 响应

javascript - NodeJS - 如何编写连接到 NodeJS 服务器并接收广播消息的客户端

c - 如何使用 C 建立 HTTP 连接?

python - 如何实现redis的pubsub超时功能?

java - 完成 HttpServletResponse 但继续处理

angular - 仅当响应成功时如何使表单路由(Angular 4)

java - Playframework 推送到 Websocket

google-chrome - 在 Chromium 重新启动之前,WebSocket 不会连接到特定主机