Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple websocket connections

Is there any advantages of having two distinct websocket connections to the same server from the same client? To me this seems a bad design choice, but is there any reason why/where it should work out better?

like image 425
Christian Avatar asked Feb 12 '12 10:02

Christian


People also ask

Can you have multiple WebSocket connections?

A server can open WebSocket connections with multiple clients—even multiple connections with the same client. It can then message one, some, or all of these clients. Practically, this means multiple people can connect to our chat app, and we can message some of them at a time.

How many connections can WebSockets handle?

The theoretical limit is 65k connections per IP address but the actual limit is often more like 20k, so we use multiple addresses to connect 20k to each (50 * 20k = 1 mil).

Would WebSockets be able to handle 1000000 concurrent connections?

With at least 30 GiB RAM you can handle 1 million concurrent sockets.

How do I stop multiple WebSocket connections?

To avoid these connections, you can use the new way of creating a Stream instance — StreamChat. getInstance('API_KEY'). This way, you can create a single instance of the chat client. Only one WebSocket connection will be opened, even in a continuous call of the useEffect hook.


1 Answers

There are several reasons why you might want to do that but they probably aren't too common (at least not yet):

  • You have both encrypted and unencrypted data that you are sending/receiving (e.g. some of the data is bulky but not sensitive).
  • You have both streaming data and latency sensitive data: imagine an interactive game that occasionally has streamed video inside the game. You don't want large media streams to delay receipt of latency sensitive normal game messages.
  • You have both textual (e.g. JSON control messages) and binary data (typed arrays or blobs) and don't want to bother with adding your own protocol layer to distinguish since WebSockets already does this for you.
  • You have multiple WebSocket sub-protocols (the optional setting after the URI) that you support and the page wants to access more than one (each WebSocket connection is limited to a single sub-protocol).
  • You have several different WebSocket services sitting behind the same web server and port. The way the client chooses per connection might depend on URI path, URI scheme (ws or wss), sub-protocol, or perhaps even the first message from client to server.

I'm sure there are other reasons but that's all I can think of off the top of my head.

like image 144
kanaka Avatar answered Sep 19 '22 00:09

kanaka