javascript Node.js EPIPE 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14702978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 22:20:48  来源:igfitidea点击:

Node.js EPIPE error

javascriptnode.jssocket.io

提问by Max Markson

I have an application composed by a node.js server plus other files and an HTML file. The HTML file is my client, it has to communicate with the node.js server. The node.js server use the objects created with the other node.js files to communicate with a PLC using an ethernet cable. So I've created a socket.io connection between the server and the client and a tcp connection between the server and the PLC.

我有一个由 node.js 服务器加上其他文件和 HTML 文件组成的应用程序。HTML 文件是我的客户端,它必须与 node.js 服务器通信。node.js 服务器使用通过其他 node.js 文件创建的对象通过以太网电缆与 PLC 进行通信。所以我在服务器和客户端之间创建了一个 socket.io 连接,在服务器和 PLC 之间创建了一个 tcp 连接。

Now the error: if I start the server and the client with all cables connected I've a correct answer from the PLC, if I disconnect the cable while running I obtain the following error:

现在出现错误:如果我在连接所有电缆的情况下启动服务器和客户端,我会得到来自 PLC 的正确答案,如果我在运行时断开电缆,我会收到以下错误:

events.js:71
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: write EPIPE
    at errnoException (net.js:770:11)
    at Socket._write (net.js:552:19)
    at Socket.write (net.js:511:15)
    at Timer.<anonymous> (C:\Users\Massimo\workspace\Scada\plc_driver\fw_driver.
js:289:20)
    at Timer.exports.setInterval.timer.ontimeout (timers.js:234:14)

I've already try to manage an error in the serverwith the code

我已经尝试使用代码管理服务器中的错误

communication_socket.on('error', function () {
    console.log('Error!');
});

I'm running node 0.8.18 and all packages are updated (I've made a npm update -g)

我正在运行节点 0.8.18 并且所有包都更新了(我做了一个npm update -g

EditThe result of the code

编辑代码的结果

process.on('uncaughtException', function(err) {
    console.log(util.inspect(err));
});

is:

是:

{ [Error: write EPIPE] code: 'EPIPE', errno: 'EPIPE', syscall: 'write' }

Any suggestion?

有什么建议吗?

回答by Old Pro

Socket IO errors are not thrown in a way that you can try/catch them. You have to add an on('error', [callback])handler to each socket. You can read some related discussion about this in Should stream.pipe forward errors?You don't say why you have a Timeout and what socket the timeout is writing to so I can't help you more.

套接字 IO 错误不会以您可以尝试/捕获它们的方式抛出。您必须为on('error', [callback])每个套接字添加一个处理程序。您可以阅读有关此内容的一些相关讨论是否应该 stream.pipe forward errors? 您没有说明为什么有超时以及超时写入的套接字,因此我无法为您提供更多帮助。

回答by Greg Willson

I had this error after a failed deploy command in Metor. I was able to fix it by running the app in debug mode, clicking through the function breakpoints, and then running the deploy script again. I hope this helps someone.

在 Metor 中部署命令失败后,我遇到了这个错误。我能够通过在调试模式下运行应用程序,单击函数断点,然后再次运行部署脚本来修复它。我希望这可以帮助别人。