Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js - share sockets between processes

I´ve read that it´s possible to share sockets between processes. Is this also possible in Node.js?

I saw the cluster api in node.js, but that´s not what I´m looking for. I want to be able to accept a connection in one process, maybe send & read a bit, and after a while pass this socket to another fully independent node.js process.

I could already do this with piping, but I don´t want to do this, since it´s not as fast as directly reading/writing to the socket itself.

Any ideas?

Update I found the following entry in the node.js documentation:

new net.Socket([options]) #
Construct a new socket object.

options is an object with the following defaults:

{ fd: null
  type: null
  allowHalfOpen: false
}
fd allows you to specify the existing file descriptor of socket. type specified underlying protocol. It can be 'tcp4', 'tcp6', or 'unix'. About allowHalfOpen, refer to createServer() and 'end' event.

I think it would be possible to set the "fd" property to the filedescriptor of the socket and then open the socket with that. But... How can I get the filedescriptor of the socket and pass it to the process that needs it?

Thanks for any help!

like image 921
Van Coding Avatar asked Dec 13 '11 13:12

Van Coding


1 Answers

This is not possible at the moment, but I've added it as a feature request to the node issues page.

Update In the mean time, I've written a module for this. You can find it here: https://github.com/VanCoding/node-ancillary

like image 53
Van Coding Avatar answered Nov 15 '22 06:11

Van Coding