Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 system 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]
}
like image 388
user961357 Avatar asked Sep 23 '11 14:09

user961357


People also ask

What are sockets in Node JS?

Web Socket is a protocol that provides full-duplex(multiway) communication i.e allows communication in both directions simultaneously. It is a modern web technology in which there is a continuous connection between the user's browser(client) and the server.

How do I create a socket server in node JS?

All we need to do is call the WebSocket Object with a URI as the parameter. const webSocket = new WebSocket('ws://localhost:443/'); And then we can create an event for the WebSocket to do something when it gets data. That's it we can now receive data from the WebSocket server.

Which of the following API creates a client net createServer?

The node:net module provides an asynchronous network API for creating stream-based TCP or IPC servers ( net. createServer() ) and clients ( net.

Which of the following API creates a client in node JS?

The Node. js Client uses the MarkLogic REST Client API to communicate with MarkLogic Server, so it uses the same security model.


1 Answers

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);
});
like image 157
usoban Avatar answered Sep 18 '22 03:09

usoban