“错误:写入EPIPE”在 Node.js 上使用 Socket.io

发布于 2024-12-25 06:55:22 字数 2370 浏览 1 评论 0原文

我手动应用了此补丁,现在一切正常。等待上游修复此问题 https://github.com/LearnBoost/socket.io-client/pull /361/files


我只是尝试遵循给出的示例并尝试使其正常工作。

Mockserver.js:

var io = require('socket.io').listen(8000);

io.sockets.on('connection', function(client) {
    console.log('+ new client');
    client.on('disconnect', function() {
        console.log('- lost a client');
    });
});

Mockclient.js:

var io = require('socket.io-client');
var socket = new io.connect('localhost', { port: 8000 });

socket.on('connect', function() {
    console.log('connected');
});

socket.on('message', function(data) {
    console.log(data);
});

然后我在另一个终端上与节点 Mockserver.js 和节点 Mockclient.js 一起运行这些对

   info  - socket.io started
   debug - client authorized
   info  - handshake authorized 14797776461130411158
   debug - setting request GET /socket.io/1/websocket/14797776461130411158
   debug - set heartbeat interval for client 14797776461130411158
   debug - client authorized for 
   debug - websocket writing 1::
+ new client
   debug - set close timeout for client 14797776461130411158
   ***************************** error occurs here ****************
   info  - socket error Error: write EPIPE
   at errnoException (net.js:632:11)
   at Object.afterWrite [as oncomplete] (net.js:470:18)
   ****************************************************************
   debug - setting request GET /socket.io/1/xhr-polling/14797776461130411158?t=1325912082073
   debug - setting poll timeout
   debug - discarding transport
   debug - cleared close timeout for client 14797776461130411158
   debug - cleared heartbeat interval for client 14797776461130411158
   debug - clearing poll timeout
   info  - transport end
   debug- set close timeout for client 14797776461130411158
   debug - cleared close timeout for client 14797776461130411158

,此时我停止了 Mockclient.js

- lost a client
   debug - discarding transport

“node Mockclient.js”的唯一输出是

The "sys" module is now called "util". It should have a similar interface.

导致套接字异常的原因?我可能错过了一些非常明显的东西。另外,其他人可以尝试我的代码来看看他们的机器上是否也有错误吗? socket.on('connect'... 内的代码也没有触发。我不完全知道为什么。

I manually applied this patch and everything works now. Waiting on upstream to fix this
https://github.com/LearnBoost/socket.io-client/pull/361/files


I'm just trying to follow the examples given and trying to get this to work.

Mockserver.js:

var io = require('socket.io').listen(8000);

io.sockets.on('connection', function(client) {
    console.log('+ new client');
    client.on('disconnect', function() {
        console.log('- lost a client');
    });
});

Mockclient.js:

var io = require('socket.io-client');
var socket = new io.connect('localhost', { port: 8000 });

socket.on('connect', function() {
    console.log('connected');
});

socket.on('message', function(data) {
    console.log(data);
});

I then run these pair with node Mockserver.js and node Mockclient.js on another terminal

   info  - socket.io started
   debug - client authorized
   info  - handshake authorized 14797776461130411158
   debug - setting request GET /socket.io/1/websocket/14797776461130411158
   debug - set heartbeat interval for client 14797776461130411158
   debug - client authorized for 
   debug - websocket writing 1::
+ new client
   debug - set close timeout for client 14797776461130411158
   ***************************** error occurs here ****************
   info  - socket error Error: write EPIPE
   at errnoException (net.js:632:11)
   at Object.afterWrite [as oncomplete] (net.js:470:18)
   ****************************************************************
   debug - setting request GET /socket.io/1/xhr-polling/14797776461130411158?t=1325912082073
   debug - setting poll timeout
   debug - discarding transport
   debug - cleared close timeout for client 14797776461130411158
   debug - cleared heartbeat interval for client 14797776461130411158
   debug - clearing poll timeout
   info  - transport end
   debug- set close timeout for client 14797776461130411158
   debug - cleared close timeout for client 14797776461130411158

at this point I stopped Mockclient.js

- lost a client
   debug - discarding transport

The only output for "node Mockclient.js" is

The "sys" module is now called "util". It should have a similar interface.

What's causing the socket exception? I'm probably missing something pretty obvious. Also, can somebody else try my code to see if the errors on their machine as well? The code inside socket.on('connect'... isn't triggering either. I don't exactly know why.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文