This question is almost same as this question:
However, since there was no good answer, I would like to ask this question again in a bit different manner:
Lets assume we have a front-end Node.js server listening raw TCP traffic:
https://nodejs.org/api/net.html#net_net_createserver_options_connectionlistener
var net = require('net');
var server = net.createServer(function(socket) {
});
server.listen(80, function() {
// http traffic here...
});
This interface is almost the same interface as with creating a http.Server
- if we would have created http.Server here, the http class would be adding it's own listener handler there on top of the TCP Socket.
The big difference is that the "raw" socket can be delegated to the Child Processes, which are other instances node.js using "send" message call.
What I would like to do is to create
- Receive a TCP Socket
- Transport it to another Process using child_process#
send
- Make the Child Process use it as a WebSocket
This is pretty much what the Cluster module is doing, but I do not want to use the Cluster module here to have control over the traffic.
For example, I would like to select the process receiving the message based on IP address, delegate the Socket to the Child Process and there import it to some WebSocket class to make it respond to HTTP / WebSocket upgrade messages.