prasad mestha
prasad mestha

Reputation: 156

socket.emit does not work for other open connections

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

Answers (1)

Kable
Kable

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

Related Questions