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);
})

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.