What's the difference between req.setTimeout & socket.setTimeout?

I have two options to set a timeout to my http request. I am not sure about their difference.

First one is:

req.setTimeout(2000,function () {
  req.abort();
  console.log("timeout");
  self.emit('pass',message);
});

Second one is:

req.on('socket', function (socket) {
  socket.setTimeout(2000);  
  socket.on('timeout', function() {
      req.abort();
      self.emit('pass',message);
  });
}

socket.setTimeout sets the timeout for the socket, e.g. to implement HTTP Keep-Alive.

request.setTimeout does internally call socket.setTimeout, as soon as a socket has been assigned to the request and has been connected. This is described in the documentation.

Hence, it's no difference, and you can choose which way to go. Of course, if you already have a request in your hands, you'd stick to the request's setTimeout function instead of digging for the underlying socket.