title: nodejs net client socket reconnect
body: <pre><code>var socket = new net.Socket();
  socket.connect(PORT, HOST, function() {
      console.log("SOCKET CONNECTED TO: " + HOST + ":" + PORT);
      socket.write("Hello World!");
  });
  socket.on("error", function() {}); // need this line so it wont throw exception
  
  // Add a "close" event handler for the client socket
  socket.on("close", function() {
      console.log("Connection lost. How do I reconnect? setTimeout?");
  });
  </code></pre>
  
  <p>How do I reconnect after it failed? Now if the connection is not successful, everything stops..  </p>
  
  <p>I've tried using setTimeout in close event, but then when the socket connects, the 'connect' event is fired multiple times.. </p>