0

This question is almost same as this question:

TCP Socket to Websocket?

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

  1. Receive a TCP Socket
  2. Transport it to another Process using child_process#send
  3. 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.

Community
  • 1
  • 1
Tero Tolonen
  • 4,144
  • 4
  • 27
  • 32
  • look to [this](http://stackoverflow.com/questions/32808988/node-js-net-sockets-websocket-without-socket-io?answertab=votes#tab-top), it may help you – Hasan A Yousef Dec 01 '15 at 08:35
  • have you managed to do this? – Unitech Jul 10 '16 at 14:32
  • @tknew sorry, not yet. Eventually I decided that node.js was not the right tool for this. – Tero Tolonen Jul 10 '16 at 15:50
  • @TeroTolonen I think Node.js is quite well fitted for proxying operations, I'm currently building a TCP load balancer: https://github.com/Unitech/taurine-lb/blob/master/lb.js and seen that module to ugprade net connection when upgrade is detected: https://www.npmjs.com/package/websocket-driver – Unitech Jul 11 '16 at 11:47

0 Answers0