Why is socket.setNoDelay() throwing an error?

主宰稳场 提交于 2019-12-24 13:19:39

问题


I have a nodejs server using socketio for real-time comms.

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);
});

Issue is, every time I call socket.setNoDelay(true); it's kicking back:

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)

I can't seem to find any documentation as to why this is happening. Anyone else see this?

Specs:

> Windows Environment  
> node version: 0.12.4 
> socket.io version: 1.3.6

回答1:


Because socket isn't a net.Socket, it's a socket.io Socket. You'll notice that there is no setNoDelay method on a socket.io Socket.

The socket.io websocket sever automatically disables Nagle on the underlying TCP socket.



来源:https://stackoverflow.com/questions/32191789/why-is-socket-setnodelay-throwing-an-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!