title: net Node.js Error: read ECONNRESET (on Windows)
body: <p>I am attempting to use the net lib in Node.js to do simple message passing.  In the <a href="http://nodejs.org/api/net.html#net_net_createserver_options_connectionlistener" rel="nofollow">example</a> on Nodejs.org they provide the following code as a basic echo server:</p>
  
  <pre><code>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');
  });
  </code></pre>
  
  <p>and a client for said server:</p>
  
  <pre><code>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');
  });
  </code></pre>
  
  <p>The example above works, however, if you remove the <code>client.end();</code> from the client code and force close the script on the client end (simulating a client crashing) the server crashes as well with the error:</p>
  
  <pre><code>Error: read ECONNRESET
      at errnoException (net.js:904:11)
      at TCP.onread (net.js:558:19)
  </code></pre>
  
  <p>I attempted to catch the error in the server code with <code>c.on("error",function(){})</code> as well as <code>server.on('error', function (e) {});</code> but in both cases the server still crashes when the client disconnects without using <code>client.end()</code></p>
  
  <p>What is the propper way of checking for this error so that the server does a <code>console.log('connection reset by peer')</code> instead of crashing?</p>
  
  <p>UPDATE:
  I tried this same code on my linux box and it seems to work just fine ... so why does it work in linux but not in windows?</p>