【发布时间】:2020-12-23 01:22:23
【问题描述】:
我正在使用 socket.io 从服务器发送和接收数据。我有一个“创建游戏”按钮客户端,允许我在服务器端创建一个新的 GameServer。从那里,我在客户端显示 game.show() 中的信息。单击“创建游戏”后,我的所有 console.log 消息(服务器端和客户端)都正在发送,但随后服务器停止并给我这个错误。
buffer.js:407
return b instanceof Buffer;
^
RangeError: Maximum call stack size exceeded
at Function.[Symbol.hasInstance] (<anonymous>)
at Function.isBuffer (buffer.js:407:12)
at hasBinary (/rbd/pnpm-volume/09796244-83a8-4b11-b56a-df421860dd93/node_modules/.registry.npmjs.org/has-binary2/1.0.3/node_modules/has-binary2/index.js:44:66)
at hasBinary (/rbd/pnpm-volume/09796244-83a8-4b11-b56a-df421860dd93/node_modules/.registry.npmjs.org/has-binary2/1.0.3/node_modules/has-binary2/index.js:58:59)
at hasBinary (/rbd/pnpm-volume/09796244-83a8-4b11-b56a-df421860dd93/node_modules/.registry.npmjs.org/has-binary2/1.0.3/node_modules/has-binary2/index.js:58:59)
at hasBinary (/rbd/pnpm-volume/09796244-83a8-4b11-b56a-df421860dd93/node_modules/.registry.npmjs.org/has-binary2/1.0.3/node_modules/has-binary2/index.js:58:59)
at hasBinary (/rbd/pnpm-volume/09796244-83a8-4b11-b56a-df421860dd93/node_modules/.registry.npmjs.org/has-binary2/1.0.3/node_modules/has-binary2/index.js:58:59)
at hasBinary (/rbd/pnpm-volume/09796244-83a8-4b11-b56a-df421860dd93/node_modules/.registry.npmjs.org/has-binary2/1.0.3/node_modules/has-binary2/index.js:58:59)
at hasBinary (/rbd/pnpm-volume/09796244-83a8-4b11-b56a-df421860dd93/node_modules/.registry.npmjs.org/has-binary2/1.0.3/node_modules/has-binary2/index.js:58:59)
at hasBinary (/rbd/pnpm-volume/09796244-83a8-4b11-b56a-df421860dd93/node_modules/.registry.npmjs.org/has-binary2/1.0.3/node_modules/has-binary2/index.js:58:59)
这是我单击“创建服务器”按钮时运行的内容
if (this.add.clicked()) {
var sid = Math.random().toString(36).substr(2, 5);
console.log('1');
emitToServer('create', sid);
console.log('2');
emitToServer('addtoserver', sid);
console.log('3');
console.log('4');
state = "GAME";
console.log('5');
}
这是我在服务器端获取“create”和“addtoserver”消息的地方
socket.on('create', function(id) {
console.log('3');
console.log("Creating server " + id);
servers.set(id, new GameServer(id));
console.log(servers);
console.log('d');
});
socket.on('addtoserver', function(sid) {
try {
console.log('1');
console.log('Adding socket to ' + servers.get(sid));
servers.get(sid).addClient(socket);
console.log('pork');
}
catch (err) {
console.log('error');
}
});
完整代码:Github
【问题讨论】:
标签: javascript node.js express socket.io