title: Reconnect to TCP/IP socket on NodeJS
body: <p>I use "net" library to create TCP connection on my nodeJs.</p>
  
  <pre><code>root.socket = net.createConnection(root.config.port, root.config.server);
  </code></pre>
  
  <p>I'm trying to handle error when remote server is down and reconnect in Cycle.</p>
  
  <pre><code>root.socket.on('error', function(error) {
          console.log('socket error ' + error);
  
          root.reconnectId = setInterval(function () {
              root.socket.destroy();
              try {
                  console.log('trying to reconnect');
                  root.socket = net.createConnection(root.config.port, root.config.server);
              } catch (err) {
                  console.log('ERROR trying to reconnect', err);
              }
  
          }, 200); 
  }
  </code></pre>
  
  <p>The trouble is that in case of remote server shutdown I still get en error and my nodeJS server stops.</p>
  
  <blockquote>
    <p>events.js:72
            throw er; // Unhandled 'error' event
                  ^ Error: connect ECONNREFUSED
        at errnoException (net.js:904:11)
        at Object.afterConnect [as oncomplete] (net.js:895:19)</p>
  </blockquote>