“错误:写入EPIPE”在 Node.js 上使用 Socket.io
我手动应用了此补丁,现在一切正常。等待上游修复此问题 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应用此补丁
https://github.com/LearnBoost/socket.io-client/pull /361/文件
Apply this patch
https://github.com/LearnBoost/socket.io-client/pull/361/files