net Node.js Error: read ECONNRESET (on Windows) -
i attempting use net lib in node.js simple message passing. in example on nodejs.org provide following code basic echo server:
var net = require('net'); var server = net.createserver(function(c) { //'connection' listener console.log('server connected'); c.on('end', function() { console.log('server disconnected'); }); c.write('hello\r\n'); c.pipe(c); }); server.listen(8124, function() { //'listening' listener console.log('server bound'); });
and client said server:
var net = require('net'); var client = net.connect({port: 8124}, function() { //'connect' listener console.log('client connected'); client.write('world!\r\n'); }); client.on('data', function(data) { console.log(data.tostring()); client.end(); }); client.on('end', function() { console.log('client disconnected'); });
the example above works, however, if remove client.end();
client code , force close script on client end (simulating client crashing) server crashes error:
error: read econnreset @ errnoexception (net.js:904:11) @ tcp.onread (net.js:558:19)
i attempted catch error in server code c.on("error",function(){})
server.on('error', function (e) {});
in both cases server still crashes when client disconnects without using client.end()
what propper way of checking error server console.log('connection reset peer')
instead of crashing?
update: tried same code on linux box , seems work fine ... why work in linux not in windows?
you can catch error adding code inside yours 'createserver' function:
process.on('uncaughtexception', function (err) { console.error(err.stack); console.log("node not exiting..."); });
Comments
Post a Comment