title: Why is socket.remoteAddress undefined on 'end' event?
body: <p>I have a simple TCP server as follows:</p>
  
  <pre><code>var net = require('net');
  var PORT = 6346;
  
  var server = net.createServer(function(socket) {
  
      socket.on('connect', function() {
          console.log('Client connected: ' + socket.remoteAddress);
          socket.write('Welcome to the server!\r\n');
      });
  
      socket.on('end', function() {
          console.log('Client disconnected: ' + socket.remoteAddress);
      });
  
      socket.on('error', function() {
          console.log('Client error: ' + socket.remoteAddress);
      });
  
      socket.on('timeout', function() {
          console.log('Client timed out:' + socket.remoteAddress);
      });
  
  
  }).listen(PORT);
  </code></pre>
  
  <p>When I connect to the server I see the expected <code>Client connected: 127.0.0.1</code> but when I disconnect I see <code>Client disconnected: undefined</code>. Why is socket.remoteAddress undefined and how can I log the IP of the client upon disconnect?</p>