I have a node.js TCP connection I created with net.connect that listens for incoming data using an Event:'data' callback. If I receive two or more messages at approximately the same time I lose them all except the first. Could the processing I'm doing in the Event:'data' callback cause me to miss incoming messages?
myConnection = net.connect(18000, 192.168.1.50);
myConnection.on('data', function(data) {
console.log("Received data");
//time consuming process here (more than a few milliseconds)
});
If two or more TCP messages (under 200 bytes each) are sent to my node app quickly (within a few milliseconds) the console only prints one message:
Received data
Is Node losing the second and later messages while running the onData callback? Does Node queue messages, so even if I'm in the callback the subsequent messages will be waiting to be read? There's a possibility that the program sending my Node app messages is not sending them correctly, but I've looked at it and it seems to be sending them.
Are you trying to output received data? I think that all your data was received correctly. There is no guarantees that count of data
events will equal count of write
methods, because it just a Stream.