title: Best practice for sending unrelated data from server to client over WebSocket connection(s)
body: <p>I am currently working on a single page web app that has a growing number of real-time widgets concurrently requiring different datasources. My question is which approach is best for using WebSockets as the vehicle for this data:</p>
  
  <p><strong>Option 1:</strong> The client opens a <strong>single socket connection</strong> with the server, then uses an API similar to the following to subscribe/unsubscribe/get/post data:</p>
  
  <pre><code>var socket = new WebSocket([URL]);
  socket.emit("subscribe", [OPTIONS]);
  socket.emit("unsubscribe", [OPTIONS]);
  socket.emit("get", [OPTIONS]);
  socket.emit("post", [OPTIONS])
  </code></pre>
  
  <p><strong>Option 2:</strong> The client opens a socket for <strong>every source of data it needs to run the widgets on the page</strong>. Keep in mind that there could be many widgets requiring many different sources of data. For example, it would look something like this:</p>
  
  <pre><code>var sock1 = new WebSocket([URL]);
  var widget1 = new Widget1(sock1);
  var sock2 = new WebSocket([URL]);
  var widget2 = new Widget2(sock2);
  var sock3 = new WebSocket([URL]);
  var widget3 = new Widget3(sock3);
  </code></pre>
  
  <p>Any insight would be much appreciated.</p>
  
  <p>Andy</p>