我手动应用了这个补丁,现在一切正常。正在等待上游解决此问题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
"nodeMockclient.js"的唯一输出是
The "sys" module is now called "util". It should have a similar interface.
套接字异常的原因是什么?我可能错过了一些显而易见的东西。另外,其他人可以试试我的代码,看看他们的机器上是否也有错误吗?socket.on('connect'…)中的代码也没有触发。我不知道为什么。
应用此补丁https://github.com/LearnBoost/socket.io-client/pull/361/files