bernd pfeffer bernd pfeffer - 1 year ago 188
Node.js Question How to emit an Array and a Variable simultaneously

Learning Node.js, Express.js ans

Made a Chat an it works so far..

Now I would like to emit to the Client, that a user has entered or left the chat by emiting a variable that indicates that...

Ist that possible?

So something like this:


var users = [];
var inout;
function updateUsers(){
io.emit('users', users, 'inout', inout);


var socket = io.connect( 'http://'+window.location.hostname+':3000' );
socket.on('users', function(data){

// how to get the 'inout' here? }

Thanks for any Help... ;)

Answer Source

The simplest way is to emit object:

var users=[]
var inout

function updateUsers(){
    io.emit('users', {users, inout});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download