开发者

disadvantages of websockets

开发者 https://www.devze.com 2023-03-09 23:50 出处:网络
I would like to know what kind of limitations there are in using websockets. Websockets is just so.. powerful. I can\'t imagine that it is without disadvantages.

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

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

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 tr开发者_运维技巧ue that with each additional connection, the quality of the connections (speed and stuff like that) will decrease?


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 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.

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.

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).

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.

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.


From what I read, this seems to be related to HTTP Server Push which I read that it is usually not recommended to use since it creates lots of connections on the server.

If I have to choose, I probably would always develop a client polling mechanism.

0

精彩评论

暂无评论...
验证码 换一张
取 消