Reputation: 156
I am doing tic tac toe multiplayer game using node.js but i am facing the following problem
1> The alert does not pop up in other open connections
//app.js
var io = require('socket.io')(server,{});
io.sockets.on('connection', function(socket){
socket.on('blockClicked',function(data){
socket.emit('newPositions',data.value);
});
socket.on('disconnect',function(){
delete SOCKET_LIST[socket.id];
});
});
//index.html
socket.on('newPositions',function(data){
blockSelected(data);
alert("recieved"+data);
});
where have i gone wrong?
Upvotes: 1
Views: 58
Reputation: 1045
You are emitting to a single socket
(client) when you call socket.emit('newPositions', data.value);
.
You can emit to all sockets by using io.sockets.emit('newPositions', data.value);
Upvotes: 1