How to set maximum size for incoming socket.io message

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

our server code:

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

our client code:

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

Is there a way to check the size of the data and refuse to accept the message before passing the data to socket.on ?

+4
source share
1 answer

I was also curious about this and dug something.

It seems that 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. 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 )

So sad that this will not work with websockets or flashsockets. Someone really tried a pull request: https://github.com/LearnBoost/socket.io/pull/888

+1
source

All Articles