3

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);
})
bring2dip
  • 886
  • 2
  • 11
  • 22

1 Answers1

4

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

Community
  • 1
  • 1
grebneke
  • 4,414
  • 17
  • 24