Ad

How To Receive Multiple Emitted Parameters With Socket.io

- 1 answer

I see the socket.io cheat sheet but it doesn't explain how to receive multiple data.

Client example:

socket.emit('foo', 'bar', 'baz');

Server Example:

socket.on('foo', (msg) => {
    console.log('message: ' + msg); //output is "message: bar"
}); 

How do I obtain baz?

Ad

Answer

Specifying the arguments in your listener works,

socket.on('foo', (msg1, ms2) => {
    console.log('message1: ' + msg1); 
    console.log('message2: ' + msg2);
}); 
Ad
source: stackoverflow.com
Ad