如何设置传入的socket.io消息的最大大小限制

我们希望我们的服务器阻止任何包含大于7 kb数据的消息。

我们的服务器端代码:

socket.on('startdata', function (data) { console.log(data.text);}); 

我们的客户代码:

  socket.emit('startdata', { text: 'testtext blah blah' }); 

有没有一种方法来检查数据大小,并拒绝接受数据传递给socket.on函数之前的消息?

我也很好奇,做了一些挖掘。

看来destroy buffer size可用,默认为100MB

重要说明: Used by the HTTP transports. The Socket.IO server buffers HTTP request bodies up to this limit. This limit is NOT applied to websocket or flashsockets. Used by the HTTP transports. The Socket.IO server buffers HTTP request bodies up to this limit. This limit is NOT applied to websocket or flashsockets.https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

很遗憾,它不适用于websocket或flashsockets。 有人尝试了这个拉请求虽然: https : //github.com/LearnBoost/socket.io/pull/888