[英]how to set maximum size limit for incoming socket.io message
we want our server to block any messages that contain data larger than 7 kb.我们希望我们的服务器阻止任何包含大于 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?有没有办法在数据传递到socket.on
function 之前检查数据大小并拒绝接受消息?
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 似乎destroy buffer size
可供使用,默认为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.
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 ) ( https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO )
So sadly, it won't work with the websockets or flashsockets. 很遗憾,它不适用于websockets或flashsockets。 Someone did try a pull request for this though: https://github.com/LearnBoost/socket.io/pull/888 有人确实尝试过拉取请求: https : //github.com/LearnBoost/socket.io/pull/888
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.