title: Websocket dealing with different data - different endpoints?
body: <p>I am curious about websockets and how to distinguish different data that it sends. I cannot really find anything clear online either, unless I am missing something that is staring me in the face. </p>
  
  <p>I have a websocket and the handshake establishes the connection. The purpose of the ws is going to provide live football scores, and a live table.</p>
  
  <p>So if it was a rest API I would probably have 2 endpoints, <code>/live-scores</code> and <code>/table</code>. My react components are interested in different data so I am wondering if there is an equivalent of endpoints in web sockets? Or how do you differentiate between different data? Should there be a separate web socket for each piece of data? </p>
  
  <p>Also, bear in mind there will be a lot more than 2 pieces of data besides live scores and table so I am thinking a different ws for each would be overkill. </p>
  
  <p>Can anyone point me in the right direction or provide an answer here? </p>
  
  <p><strong>TLDR</strong> Do you create a websocket for each different group of data (for want of a better way of describing this) or is there just one websocket and if so what is the best way for the client to distinguish what kind of data it is receiving?</p>
  
  <p>If the question makes no sense let me know and I will try and make it clearer.</p>
  
  <p>My starting code is here:</p>
  
  <pre><code>import sockjs from 'sockjs';
  
  const ws = sockjs.createServer({
      sockjs_url: 'http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js',
  });
  
  ws.on('connection', connection =&gt; {
      connection.on('data', m =&gt; {
          const message = m ? JSON.parse(m) : {};
          if (message.type === 'register') {
              connection.write(
                  JSON.stringify({
                      address: message.address,
                      body: {
                          message: 'Hello World!',
                      },
                  })
              );
          }
      });
  });
  export default ws;
  </code></pre>