node-cluster-socket.io
node-cluster-socket.io copied to clipboard
Using Express.js instead of Net
Is it possible to use Express.js instead of Net?
I guess Express would be the default usecase for most users. Currently i do have 2 servers: Net for Socket.io (like mentioned here) and Express.js for http requests. Now i have the problem to activate SSL and Cors on Net while it was pretty easy on Express.js.
Is "net" even capable of using http long-polling? The node.js documentation says net.createServer() creates a TCP server but no http server?
Same question here. How can you get connection out of Express? I would like to have smth like first page on the main script and then pass it to the worker i choose on the page... When i use Express instead of net on the first connect, a can´t end the connection to the first Express and pass it forward.
yeah, this example doesn't use socket.io at all, it just shows how to move tcp connection.
Actually SSL needs to be handled by NGINX before it gets to Net and then Socket.io. Works fine for me.
Im still curious if its possible to use only Express.
@MickL how could you restore a tcpnet connection handle to a socket.io instance?
What do you mean by restore? Net just forwards the TCP connection to the child process and socket.io picks it up and has a direct tcp connection to the user then without Net involved.
@MickL for restore I mean just the same as you say
socket.io picks it up
how to pick the raw tcp connection up as a socket.io's client socket?? we can emit and receive event at the later, but not the low-level connection.
Im pretty sure the code here just forwards the tcp connection and socket.io gets it as normal. What do you want to archive?
in this code, we get a connection from master process,
but its class is net.Socket
,
i can't emit and recv event on it with a socket.io client
process.on('message', function(message, connection) {
if (message !== 'sticky-session:connection') {
return;
}
// Emulate a connection event on the server by emitting the
// event with the connection the master sent us.
server.emit('connection', connection);
connection.resume();
//NO EFFECT
connection.emit('action', '---------');
connection.on('action', function(msg) {
console.log('recv action', msg);
});
});