您仍然需要从您的计算机向网站的服务器来回发送请求。 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.
延迟比较:-
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/