开发者

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

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

My question is: Does "new Socket" creates a operating syst开发者_如何转开发em socket object file, and if so, how can I get the Socket File Descriptor or File Name?

I'm not sure if this is how I should create a Socket, but here is the case:

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]
}


Well when you connect a socket, socket.fd is not null, at least not in my case, so provide an example case please.

Note that you can also specify existing file descriptor at socket creation.

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);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜