Does Node.js create a "new Socket" Unix file socket?

I have been working with node.js for the past few weeks and I need to implement the FAST-CGI protocol. The problem is that when I create a UNIX socket (via the "new Socket"), I need to get the file name or file descriptor. But socket.fd is null (default parameter).

My question is: โ€œNew Socketโ€ creates an operating system socket object file, and if so, how can I get a file descriptor for a file or file name?

I'm not sure that this is how I should create Socket, but like this:

node:

var net = require(net) var socket = new net.Socket() console.log(socket); { bufferSize: 0, fd:null, type: null, allowHalfOpen: false, _writeImpl: [Function], _readImpl: [Function], _shutdownImpl: [Function] } 
+6
source share
1 answer

Well, when you plug in a socket, socket.fd is not null, at least not in my case, so give an example.

Note that you can also specify an existing file descriptor when creating a socket .

Edit:

 var net = require('net'), fs = require('fs'), sock; // Create socket file fs.open('/tmp/node.test.sock', 'w+', function(err, fdesc){ if (err || !fdesc) { throw 'Error: ' + (err || 'No fdesc'); } // Create socket sock = new net.Socket({ fd : fdesc }); console.log(sock); }); 
+6
source

Source: https://habr.com/ru/post/897905/


All Articles