Reputation: 885
I have written this code that sends packet to a socket and reads from it. But when i run it , i get the data from socket but the code throws an error by saying read ECONNRESET. Am I doing anything wrong?
var client = net.connect({port:remotePort, host:remoteIpAddress},function(){
client.write(packet);
});
client.on('data',function(chunkData){
console.log(chunkData);
client.end();
});
client.on('end',function(){
console.log("Reading end");
});
client.on('error', function(err){
console.log("Error: "+err.message);
})
Upvotes: 3
Views: 20033
Reputation: 4494
Your code should be ok. ECONNRESET
means the other side of the socket unexpectedly aborted the connection. It's not your client code causing this error.
See also previous question on the same topic
Upvotes: 4