title: Can you send a unix domain file descriptor over another unix domain socket in node.js?
body: <p>In Node.js. 
  Is it possible to send a unix domain socket file descriptor over already established unix domain socket ?</p>
  
  <p>I have the following example but I am not sure how and if it's even possible to receive the file descriptor on the other end in usable form.</p>
  
  <p>currently getting file descriptor type error on the server side </p>
  
  <p>In the example I have the client connecting to the server side via unix socket and that works fine, then once the connection is established I try to create a new server with new unix socket and pass that file descriptor to the server so server can use it. </p>
  
  <p>Server side:</p>
  
  <pre><code>var net = require('net');
  var socket = '/tmp/testing.node.sock';
  var fs = require('fs');
  
  if (fs.existsSync(socket)) {
      fs.unlinkSync(socket);
  }
  
  
  var server = net.createServer(function(c) { 
      console.log('server connected');
      c.on('end', function() {
          console.log('server disconnected');
      });
      c.on('error', function(e) {
          console.log(e);
      });
  
      c.on('data', function(data) {
          console.log("data received");
          console.log(data.toString());
  
          // creating new socket with passed fd
          var newsock = new net.Socket({fd:data}); // how do I convert it here to file descriptor - if even possible 
          console.log(newsock);
      });
  });
  
  
  
  server.listen(socket, function() { 
      console.log('server bound');
  
  
  });
  </code></pre>
  
  <p>client side:</p>
  
  <pre><code>var net = require('net');
  var socket = '/host/testing.node.sock';
  var fs = require('fs');
  
  client = net.connect({path: socket}, function () {
  
      // here we create a new server that we want the fd passed to other server
      var newSock = '/tmp/testing.node.sock';
      if (fs.existsSync(newSock)) {
          fs.unlinkSync(newSock);
      }
      // create a new server 
      var server = net.createServer(function (c) { //'connection' listener
          console.log('server connected');
          c.on('end', function () {
              console.log('server disconnected');
          });
          c.on('error', function (e) {
              console.log(e);
          });
  
          c.on('data', function (data) {
              console.log("data received");
              console.log(data);
          });
  
      });
  
  
      server.listen(newSock, function () { //'listening' listener
          console.log('server bound');
  
          console.log(server);
  
          // here we want to pass the new fd 
          client.write(new Buffer(server._handle.fd));
      });
  
  
  });
  </code></pre>
  
  <p>Thanks </p>