websockets的缺点 [英] disadvantages of websockets

查看:15
本文介绍了websockets的缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用 websockets 有哪些限制.

I would like to know what kind of limitations there are in using websockets.

Websockets 是如此……强大.我无法想象它没有缺点.

Websockets is just so.. powerful. I can't imagine that it is without disadvantages.

比如说,可以同时连接到服务器的用户数量是多少(如果我正在创建一个游戏并且用户将通过 WebSockets 连接到游戏,那么任何时候能够连接的用户数量将受到限制?)

Say, what is the number of users that can simultaneously connect to a server (if I'm creating a game and users will connect to the game through WebSockets, what will limit the number of users able to connect at any one time?)

每增加一个连接,连接的质量(速度和类似的东西)是否也会降低?

Also is it true that with each additional connection, the quality of the connections (speed and stuff like that) will decrease?

推荐答案

优缺点当然取决于具体用例,但我会尽量指出 WebSocket 和 HTTP 之间的一些差异.

The advantages and disadvantages will of course depend on the specific use case, but I'll try to point out some differences between WebSocket and HTTP.

WebSocket 比 HTTP 更复杂.您可以与 telnet 客户端建立 HTTP 连接,但您可能无法与 WS 建立相同的连接.即使您忽略了握手要求(包括使用 SHA1 哈希函数),您也将无法正确屏蔽和构建要发送的数据,并且服务器将关闭连接.

WebSocket is more complex than HTTP. You can establish an HTTP connection with a telnet client, but you probably cannot do the same with WS. Even if you ignored the handshake requirements (which include the use of the SHA1 hash function), you would then be unable to properly mask and frame the data to be sent, and the server would close the connection.

正如 Uwe 所说,WebSocket 连接旨在比 HTTP 连接更持久.如果您只想每 30 分钟接收一次更新,您将需要使用 HTTP.如果您想每秒接收更新,WebSocket 可能是更好的选择,因为建立 HTTP 连接需要很多时间.

As Uwe said, WebSocket connections are intended to be more persistent than HTTP connections. If you only want to receive an update every 30 minutes, you will want to go with HTTP. If you want to receive updates every second, a WebSocket might be a better option, because establishing an HTTP connection takes a lot of time.

要建立 HTTP 连接,首先要建立 TCP 连接(SYN、SYN/ACK、ACK),然后发送带有相当大标头的 GET 请求,最后接收服务器的响应(以及另一个大标头)).

To establish an HTTP connection, you first have to establish a TCP connection (SYN, SYN/ACK, ACK), then send a GET request with a pretty big header, then finally receive the server's response (along with another big header).

使用开放的 WebSocket,您只需接收响应(无需请求),它带有一个更小的标头:从两个字节的小帧到 10 个字节的可笑的大帧(在千兆字节范围内).

With an open WebSocket you simply receive the response (no request needed), and it comes with a much smaller header: from two bytes for small frames, up to 10 bytes for ridiculously large frames (in the gigabyte range).

您需要权衡两种成本(保持连接打开与建立新连接)来决定两种协议.

You need to weigh the two costs (keeping a connection open vs establishing a new connection) to decide between the two protocols.

注意:此答案基于协议的当前草案(draft-ietf-hybi-thewebsocketprotocol-09).WebSocket 发展迅速,许多实现仍基于较旧的草案,在最终确定之前,某些细节可能会发生变化.

Note: this answer is based on the current draft of the protocol (draft-ietf-hybi-thewebsocketprotocol-09). WebSocket is evolving rapidly, many implementations are still based on older drafts, and some details may change before it is finalized.

这篇关于websockets的缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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