2

I'm pretty new here. I'm trying to use the emit function in this case with no luck :(.

Server Side:

socket.on('newUser', function(msg){ ConnectedSockets ++; var player; player = new Player(); player.CreatePlayer(msg.id, msg.name, msg.status); socket.id=msg.id; socket.name=msg.name; sockets[socket.id] = socket; for(i in sockets){ var myVar=sockets[i].name; socket.emit('listing',{name: myVar} ); } }) ; 

Client Side:

socket.on('listing', function(msg){ $('#list').val($('#list').val() + "\n"+msg.name); }) ; 

When I send newUser event on node.js console, no messages appear in response. If I write sys.puts("socket name:"+ myVar) in the for cycle, all the socket names appear as I expected.

Why the client doesn't receive any answer (no error message or any kind of warning)? :)

0

1 Answer 1

2

Problematic line:

socket.id=msg.id; 

In Socket.io socket.id has a predefined value, and it must not be changed. That caused the error.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.