socket.io server and android client
<p>I have a socket server with socket io and nodejs and a android application as client here is the server code : </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var server = require('http').createServer();
var io = require('socket.io')(server);
var UserId;
var RequestCode;
io.sockets.on('connection', function(socket){
 socket.on('data', function(data) {
  var d = JSON.parse(data);
  UserId = d.user_id;
  RequestCode = d.request_code;
 });
  var mj = setInterval(function(){
  
  var mysql = require('mysql');
  var connection = mysql.createConnection({
    host     : 'localhost',
    user     : 'root',
    password : '***',
    database : '***'
  });
  
  connection.connect();
   
  connection.query("SELECT * FROM buffer WHERE user_id = " + UserId + " AND request_code = " + RequestCode + ";"
  ,function(err, rows, fields) {
    for(i = 0; i &lt; rows.length; i++)
    {
   var jj = rows[i]['pm'];
   socket.emit('answer', jj);
   executeQuery("DELETE FROM buffer WHERE id = " + rows[i]['id']);
    }
  });
  connection.end();
 }, 1000);
});
function executeQuery(sql)
{
 var mysql = require('mysql');
 var connection = mysql.createConnection({
   host     : 'localhost',
   user     : 'root',
   password : '***',
   database : '***'
 });
 connection.connect();
 connection.query(sql);
 connection.end();
}
server.listen(8087, '***); </code></pre>
</div>
</div>
</p>

<p>my server does this basically : when a client connects and send a data it recieves the data and insert its answer to a table ... I have a timer thing that checks the table every second and see if there is any data for any client if there is It uses  emit  to send that data to user and then  . when one client is connected everything is ok but :
when more than one clients connect to server then the emit thing works sometimes like it sends the data for the worng client sometimes and somtimes it sends it correctly  the client side is really simple and im sure that its not the clients what am I missing here ? or what is the better solution ?  </p>