Domanda

I know I am overthinking this... but the answer is just not clicking.

I have two servers, one a TCP socket server and the other a SockJS server. I need to combine both of their connection events into one super event:

async.parallel({
  tcp: function (done) {
    self._tcp = net.createServer(function (sock) {
      done(null, sock);
    });
  },
  ws: function (done) {
    self._ws = sockjs.createServer(function (sock) {
      done(null, sock);
    });
  }
}, function (err, results) {
   // This never gets fired!!!
   // But I'd like to do stuff here with both 
   // socket instances – you know, like piping =)
});

Originally I had the TCP connection nested within the WS connection, but that's proving to be problematic as it requires a rigid connection sequence. What I really need is an event that is fired when both connections have been established and have access to their respective sock instances. Help jogging the brain would be much appreciated!

È stato utile?

Soluzione

This might be overly simple - but looking at the sockjs documentation, there isn't a callback function for createServer() - so it's never going to loop back through the callback of your parallel function.

Try just calling done(null, sock); right after you do socket.createServer(); and you should be all set.

Doc: https://github.com/sockjs/sockjs-node

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top