【发布时间】:2018-10-10 02:47:47
【问题描述】:
我正在尝试通过将响应发送到 ws 客户端并等待其响应来发送对快速请求的响应。所以我需要将res 对象发送给客户端(我找不到其他方法)。
这就是我所做的:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket) => {
socket.on('res', (e) => {
e.res.send(e.data)
})
})
app.get('/endpoint', (req, res) => {
io.emit('req', { data: 'test', res: res });
});
http.listen(3000);
但是,在转到 /endpoint 之后,我收到了这个错误:
RangeError:超出最大调用堆栈大小
在 Function.isBuffer (buffer.js:428:36)
在 hasBinary (/workspace/socketio/node_modules/has-binary2/index.js:42:87)
在 hasBinary (/workspace/socketio/node_modules/has-binary2/index.js:56:59)
在 hasBinary (/workspace/socketio/node_modules/has-binary2/index.js:56:59)
在 hasBinary (/workspace/socketio/node_modules/has-binary2/index.js:56:59)
在 hasBinary (/workspace/socketio/node_modules/has-binary2/index.js:56:59)
在 hasBinary (/workspace/socketio/node_modules/has-binary2/index.js:56:59)
在 hasBinary (/workspace/socketio/node_modules/has-binary2/index.js:56:59)
在 hasBinary (/workspace/socketio/node_modules/has-binary2/index.js:56:59)
在 hasBinary (/workspace/socketio/node_modules/has-binary2/index.js:56:59)
【问题讨论】:
标签: javascript node.js express socket.io