title: Using Socket.io with multiple clients connecting to same server
body: <p>Server-</p>
  
  <pre><code>  var dgram = require('dgram');
    var client= dgram.createSocket('udp4');
  
      /** @requires socket.io */
    var io = require('socket.io')(http);
  
    /** Array of clients created to keep track of who is listening to what*/
        var clients = [];
  
        io.sockets.on('connection', function(socket, username){
          /** printing out the client who joined */
          console.log('New client connected (id=' + socket.id + ').');
  
          /** pushing new client to client array*/
          clients.push(socket);
  
  
  
        /** listening for acknowledgement message */
        client.on('message', function( message, rinfo ){
          /** creating temp array to put data in */
          var temp = [];
          /**converting data bit to bytes */
          var number= req.body.size * 2
          /** acknowledgement message is converted to a string from buffer */
          var message = message.toString();
          /** cutting hex string to correspong to requested data size*/
          var data = message.substring(0, number);
          /** converting that data to decimal */
          var data = parseInt(data, 16);
          /** adding data to data array */
          temp[0] = data
          /** emitting message to html page */
          socket.emit('temp', temp);
        });
  
        /** listening if client has disconnected */
        socket.on('disconnect', function() {
            clients.splice(clients.indexOf(client), 1);
            console.log('client disconnected (id=' + socket.id + ').');
            clearInterval(loop);
        });
      });
    }
  });
  </code></pre>
  
  <p>Client-</p>
  
  <pre><code>var socket = io.connect('192.168.0.136:3000');
  
  
  
    socket.on(temp', function(temp){
        var temp= temp.toString();
      var message= temp.split(',').join("&lt;br&gt;");
      $('#output').html('&lt;output&gt;' + message + '&lt;/output&gt;');
    });
  </code></pre>
  
  <p>When a client connects, a random number called temp is emitted to the client. The above code works when one client connects to the server. Now how can you set a new connection each time? So that if one tab is opened, it gets its own random message back, while when another tab opens, it gets its own random message back. </p>