title: Swap websocket connections between multiple clients
body: <p>I'm trying to monitor two computers, and show their information to a website. In the server I use javascript websocket and the two computers sends information to server IP. I want to monitor in the same page the two computers status and over 10 messages recived, swap the information to show.</p>
  
  <p>This is my actual code, but that way connects the tow sockets at the same time. I want to open a socket with 1st IP, recive 10 messages, close connection and open the second IP. After reciveing 10 messages of IP2, close connecction, open socket with 1st IP and repeat the process. </p>
  
  <p>It's better to use node.js ? I have never used it and i din't know the potential of this.</p>
  
  <p>Can somebody help me ? </p>
  
  <p>Sorry for my poor english.</p>
  
  <pre><code>var IPs =  ['ws://localhost:9000','ws://localhost:8000']; 
  
  while(1){
      IPs.forEach(function(IPactual){
              var socket = new WebSocket(IPactual);
              console.log(socket.readyState);
              socket.onopen = function() {
                  console.log('%c Connected to ' + socket.url, "color:orange ");
              }
  
              socket.onclose = function() {
                  console.log('%c Disconnected from ' + socket.url, "color: red");
              }
  
              socket.onerror = function(e) {
                  console.log('%c Ooops... ' + e, "color: red");
              }
  
              var messages= 0;
              socket.onmessage = function(e) {
                  messages++;
                  console.log(messages);
  
                  // WRITE TO HTML THE INFORAMTION RECIVED
  
                  if (messages==10){
                      socket.onclose = function () {}; 
                      socket.close()
  
                  }
              }
  
      })
  }
  </code></pre>