[英]Send response multiple times?
I have a little problem. 我有一点问题。
I have a node application on a server, that serves a website as control panel for a client based application. 我在服务器上有一个节点应用程序,该服务器将网站用作基于客户端的应用程序的控制面板。
Example: 例:
That works fine, on time. 按时工作正常。 The second time the server crashes because the header is already sent.
服务器第二次崩溃,因为标头已经发送。
//Comand comes in
app.get('/create/:id/:package', function (req, res) {
if (io.sockets.connected[req.params.id]) {
//Command is sent to client
io.sockets.connected[req.params.id].emit('control', {type: 'create', packageName: req.params.package});
//Output is coming back
socket.on('createOutput', function (data) {
//Response sent back to http request (works once)
res.send(data);
});
}
});
Is there any way to work around this behavior? 有什么办法可以解决此问题?
You can send the data only once with socket.once
: 您只能使用
socket.once
发送一次数据:
socket.once('createOutput', function (data) {
//Response sent back to http request (works once)
res.send(data);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.