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

时间:2013-03-30 18:09:10

标签: javascript node.js socket.io

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

我们的服务器端代码:

socket.on('startdata', function (data) {

        console.log(data.text);});

我们的客户代码:

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

有没有办法在数据传递给socket.on函数之前检查数据大小并拒绝接受消息?

1 个答案:

答案 0 :(得分:1)

我也对此感到好奇并做了一些挖掘。

似乎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.https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

很遗憾,它不适用于websockets或flashsockets。有人确实尝试过拉取请求:https://github.com/LearnBoost/socket.io/pull/888