Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disadvantages of websockets

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 true that with each additional connection, the quality of the connections (speed and stuff like that) will decrease?

like image 674
Pacerier Avatar asked Jun 03 '11 08:06

Pacerier


People also ask

Why WebSockets are not used?

Avoid using WebSockets if only a small number of messages will be sent or if the messaging is very infrequent. Unless the client must quickly receive or act upon updates, maintaining the open connection may be an unnecessary waste of resources.

Why WebSockets are not reliable?

It is worth to mention that WebSockets give us only an illusion of reliability. Unfortunately, the Internet connection itself is not reliable. There are many places when the connection is slow, devices often go offline, and in fact, there is still a need to be backed by a reliable messaging system.

Is WebSocket slower than HTTP?

Websocket is said to be faster than http because it provides full duplex communication. So, both client and server can communicate at the same time.

Is it safe to use WebSockets?

WSS is secure, so it prevents things like man-in-the-middle attacks. A secure transport prevents many attacks from the start. In conclusion, WebSockets aren't your standard socket implementation. WebSockets are versatile, the established connection is always open, and messages can be sent and received continuously.


1 Answers

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.

like image 61
suriv Avatar answered Sep 19 '22 05:09

suriv