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

时间:2012-01-07 05:02:11

标签: javascript node.js socket.io serverside-javascript

我手动应用了这个补丁,现在一切正常。等待上游解决此问题 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

“节点Mockclient.js”的唯一输出是

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

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

1 个答案:

答案 0 :(得分:3)