express.io icon indicating copy to clipboard operation
express.io copied to clipboard

How do you pass a callback to emit to express.io.route

Open chicheongweng opened this issue 10 years ago • 1 comments

With pure socket io, I can pass callback to emit as follows:

server side: socket.on('data', function(data, callback) { process data from client; callback && callback(true); }

client side: socket.emit('data', {name:value}, function(data) { console.log('The server got something'); }

But if I use express.io on the server side, the below code does not work because the callback is null. express.io.route('data', function(req, callback) { process data from client; callback && callback(true); <--- This does not work because callback is undefined }

So how do I do the callback to client side's emit on the server side using expressio?

chicheongweng avatar Dec 17 '14 05:12 chicheongweng

needed this functionality too, trying this:

app.io.route('ready', function (socket) {
    console.log('Client connected');
    socket.io.emit('news', { hello: 'world' });
    socket.io.route('my other event', function (data) {
        console.log(data);
    });
});

gives "undefined is not a function" error

woojoo666 avatar Apr 04 '15 15:04 woojoo666