【发布时间】:2020-03-07 07:12:24
【问题描述】:
我正在构建一个应用程序,让您可以加入游戏,然后接收来自游戏中其他玩家的更新。在添加房间功能之前,套接字工作正常,但现在客户端不会收到广播到各自房间的消息。
服务器代码:
io.on('connection', client => {
// JOIN GAME
client.on('join-game', ({gameId, playerId}) => {
console.log(gameId)
client.join('new-room', () => {
io.sockets.in('new-room').emit('player-joined-game', 'Is this thing on?);
})
});
客户代码:
componentDidMount = () => {
const socket = socketIOClient('localhost:5000');
socket.on('player-joined-game', game => {
console.log(game)
})
}
服务器收到消息,但客户端没有打印'Is this thing on?'
【问题讨论】:
标签: reactjs express socket.io react-redux