Updating variable in nodejs

I wrote a simple server in node js.

var tls = require("tls"), fs = require("fs"), sys = require("sys");
//Number of messages received
var received=0;

var options = {
    key: fs.readFileSync("certs/keys/server.key"),//Server private key
    cert:fs.readFileSync("certs/certs/server.crt"),//Server cert.
    requestCert: true,//Require client to send it's certificate
    rejectUnauthorized:true,
    ca:fs.readFileSync("certs/certs/userA.crt") //Root certificate,
};


//Server instance with connection request callback
var server = tls.createServer(options,function(socket){ 
    //Add a listener for receiving data packets
    socket.addListener("data", function(data){      
        received++;     
    });
}).listen(2195,function(){
    console.log("Server started");
});

I also have java client application which makes multiple (300) connections to the server and sends messages. The problem is value of variable "received" does not match with the value of "send" on java side. For. example if I send 100,000 messages from java application, the server shows value of received as 80,000, even though all the messages are successfully received by the server.

I think the issue is variable received is updated by multiple callbacks at the same time and hence the final value is getting messed up. Any idea on how i can get this resolved?

TCP/IP does not guarantee that the number of packets sent matches the number of packets received. So it can happen that two or more consecutive sent packets get "combined" into one. (See -> Nagle's algorithm) or they get split (See -> IP fragmentation) if they dont fit into the MTU.