I am trying to get two clients (players) to communicate with each other (exchanging, for example, strings) through socket.io. I have this code on clients (gameId is defined in the code):
var chat = io.connect('http://localhost/play'); chat.emit(gameId+"", { guess: "ciao" }); chat.on(gameId+"", function (data) { alert(data.guess); });
While on the server I have this (which is one of the first things I do, not routing, of course)
var messageExchange = io .of('/play') .on('connection', function (socket) { socket.emit('message', { test: 'mex' }); });
Basically I create a channel, and then, when users connect, they use the channel to exchange the message of the king "gameId", which only both of them can read (using the material on.(gameId+"" ... My problem is that when players connect (first, and then others), the first connected should warn the data received (because the second that connected, issued a message). Do any of you know why this does not happen?
Thanks.
Masiar
source share