Reputation: 197
socket.on('data', function(data, socket){
console.log(socket);
worker.handle(data, socket);
When I do this, the output is undefined
. Why do I get that instead of socket data?
This passes an (undefined) socket to my worker script, which then tries to write to that undefined socket, crashing the server.
Upvotes: 1
Views: 211
Reputation: 42577
Your callback is wrong. socket.on('data') takes a function with just one parameter -- the data. Your 2nd parameter is not valid and won't be called.
You should (IMHO) just be able to refer to your 'socket' variable within the context of the callback.
Upvotes: 2