【发布时间】:2013-12-07 03:37:29
【问题描述】:
全部,
尝试使用node.js隔离别人通过node.js中的child_process API创建的JS插件。我无法让子进程与父进程交互,运行此代码没有错误,但客户端无法发送或接收消息,或写入 console.log,所以我假设 JS 没有运行。我确实收到一条控制台消息,说明调试器正在从父级和客户端运行。代码几乎直接来自 node.js API 文档,所以我不确定为什么这不起作用。可能是 Windows 环境有问题?
父代码:
var fork = require('child_process').fork;
console.log('Starting plugin server...');
var myChild = fork('client.js');
myChild.on('message', function (msg) {
console.log('PARENT got message:', msg)
});
myChild.send({ hello: 'world' });
client.js:
console.log("child");
process.on('message', function (msg) {
console.log('CHILD got message:', msg)
process.send({msg: 'Message receivd & resent from the child.'})
});
process.send({msg: 'Message from the child.'});
输出:
debugger listening on port 5858
Starting plugin server...
debugger listening on port 5858
我正在使用 Windows 8.1、Visual Studio 2013 Pro 以及用于 node.js 插件的新工具。
任何指针表示赞赏。我是 node.js 的新手,所以可能会犯一个愚蠢的错误??
【问题讨论】:
-
好的,这里再进一步。似乎是 Visual Studio 环境或 VS 的 node.js 工具。在没有调试器(ctrl-F5)的情况下运行应用程序时,我得到了正确的行为。可能与使用相同调试 TCP 端口的孩子有关,或者 VS 调试器在运行 2 个节点实例时感到困惑。这仍然是一个问题,因为我需要能够调试插件,但会尝试 VS node.JS 工具中的远程调试器选项。我猜父母和孩子使用相同的调试端口将是一个问题,并且 VS node.js 工具无法更改端口。
标签: javascript windows node.js child-process