为什么socket.setNoDelay()会引发错误?
问题描述:
我有一个使用socketio进行实时通信的nodejs服务器。为什么socket.setNoDelay()会引发错误?
var app = require('http').createServer(handler)
, io = require('socket.io')().listen(app)
function init() {
app.listen(process.env.PORT || 8888);
};
io.sockets.on('connection', function (socket) {
socket.setNoDelay(true);
onSocketConnection(socket);
});
问题是,我每次调用socket.setNoDelay(true);它的反击:
E:[path]\server.js:58
socket.setNoDelay(true);
^
TypeError: undefined is not a function
at Namespace.<anonymous> (E:\[path]\server.js:58:12)
at Namespace.emit (events.js:107:17)
at Namespace.emit (E:\path]\node_modules\socket.io\lib\namespace.js:205:10)
at E:\[path]\node_modules\socket.io\lib\namespace.js:172:14
at process._tickCallback (node.js:355:11)
我似乎无法找到任何文档,为什么发生这种情况。其他人看到这个?
规格:
> Windows Environment
> node version: 0.12.4
> socket.io version: 1.3.6
答
因为socket
不是net.Socket
,这是一个socket.io Socket
。您会注意到socket.io Socket
上没有setNoDelay
方法。
socket.io websocket服务器automatically disables Nagle on the underlying TCP socket。
找到底层'.setNoDelay()'调用的好方法。 engine.io是否使用链接的'github.com/websockets/ws'库? – kdbanman
[是](https://github.com/socketio/engine.io/blob/1.5.2/lib/server.js#L14) – josh3736