[英]Maximum call stack size exceeded (web socket in node.js)
我正在nodejs中实现Web套接字以对dynamodb进行查询,但出现此错误:buffer.js:398 Buffer.isBuffer = function isBuffer(b){^
RangeError: Maximum call stack size exceeded
at Function.isBuffer (buffer.js:398:36)
at hasBinary (E:\ProyectoSMET\Aprendiendo_nodejs_y_Angular\angular-socket-io-example-master\server\node_modules\has-binary2\index.js:44:66)
at hasBinary (E:\ProyectoSMET\Aprendiendo_nodejs_y_Angular\angular-socket-io-example-master\server\node_modules\has-binary2\index.js:58:59)
at hasBinary (E:\ProyectoSMET\Aprendiendo_nodejs_y_Angular\angular-socket-io-example-master\server\node_modules\has-binary2\index.js:58:59)
at hasBinary (E:\ProyectoSMET\Aprendiendo_nodejs_y_Angular\angular-socket-io-example-master\server\node_modules\has-binary2\index.js:58:59)
at hasBinary (E:\ProyectoSMET\Aprendiendo_nodejs_y_Angular\angular-socket-io-example-master\server\node_modules\has-binary2\index.js:58:59)
at hasBinary (E:\ProyectoSMET\Aprendiendo_nodejs_y_Angular\angular-socket-io-example-master\server\node_modules\has-binary2\index.js:58:59)
at hasBinary (E:\ProyectoSMET\Aprendiendo_nodejs_y_Angular\angular-socket-io-example-master\server\node_modules\has-binary2\index.js:58:59)
at hasBinary (E:\ProyectoSMET\Aprendiendo_nodejs_y_Angular\angular-socket-io-example-master\server\node_modules\has-binary2\index.js:58:59)
at hasBinary (E:\ProyectoSMET\Aprendiendo_nodejs_y_Angular\angular-socket-io-example-master\server\node_modules\has-binary2\index.js:58:59)
.....这是我的代码:
let app = require('express')();
let http = require('http').Server(app);
let io = require('socket.io')(http);
const AWS = require('aws-sdk');
AWS.config.update({ region: 'us-west-2' });
docClient = new AWS.DynamoDB.DocumentClient();
const tableName = 'Dispositivo';
var datos=docClient.scan({
TableName: tableName
},(err, data)=>{
if(err) {
console.log(err);
} else {
console.log(data);
}
});
io.on('connection', (socket) => {
// Log whenever a user connects
console.log('user connected');
// Log whenever a client disconnects from our websocket server
socket.on('disconnect', function(){
console.log('user disconnected');
});
// When we receive a 'message' event from our client, print out
// the contents of that message and then echo it back to our client
// using `io.emit()`
socket.on('message', (message) => {
console.log("Message Received: " + message);
io.emit('message', {type:'new-message', text: datos});
});
});
// Initialize our websocket server on port 5000
http.listen(5000, () => {
console.log('started on port 5000');
});
您正在尝试发出存储在变量datos
。 由于该函数是异步的,因此您实际上并不存储在回调函数中获得的数据。 您正在console.logging它,但没有将其存储在变量中。 这就是io.emit
失败的原因。 我建议您阅读javascript中异步函数的工作方式。 在此处详细了解许多新的javascript开发人员所遇到的问题: 如何返回异步调用的响应?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.