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 ?
2 Answers
Reset to default 2use 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