最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to set maximum size limit for incoming socket.io message - Stack Overflow

programmeradmin3浏览0评论

we want our server to block any messages that contain data larger than 7 kb.

our serverside code:

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

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

our clientside code:

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

is there a way to check the data size and refuse to accept the message before the data gets passed to the socket.on function ?

we want our server to block any messages that contain data larger than 7 kb.

our serverside code:

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

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

our clientside code:

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

is there a way to check the data size and refuse to accept the message before the data gets passed to the socket.on function ?

Share Improve this question asked Mar 30, 2013 at 18:09 Michael MoellerMichael Moeller 9064 gold badges12 silver badges27 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

use buffer size

require('socket.io')(server, {
    maxHttpBufferSize: 1e9
});

I was also curious about this and did some digging.

It seems destroy buffer size is available for use which defaults to 100mb

important note: 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./LearnBoost/Socket.IO/wiki/Configuring-Socket.IO)

So sadly, it won't work with the websockets or flashsockets. Someone did try a pull request for this though: https://github./LearnBoost/socket.io/pull/888

发布评论

评论列表(0)

  1. 暂无评论