由于某种原因,当我想向给定房间的插座发出信号时,我什么也没得到。但是,当我仅向一个特定的套接字发出信号时,它确实起作用。这是我的代码:
//client side
var socket = io();
var room = "abc";
startButton.onclick = function(){
socket.emit('startGame',{room:room});
}
socket.on('startGameResponse', function(msg){
console.log(msg);
});
//server side
var serv = require('http').Server(app);
var io = require('socket.io')(serv,{});
io.sockets.on('connection', function(socket){
socket.on('startGame',function(data){
var room = data.room;
socket.join(room);
io.sockets.in(room).emit('startGameResponse','player joined');
}