我已使用
在Node.js中打开了WebSocket服务器[
{
“id”: "string",
"images": [
null
],
"quantity": 0,
“description": "string"
},
{
“id”: "string",
"images": [
null
],
"quantity": 0,
“description": "string"
}
]
然后可以与客户端(浏览器js脚本)进行通信,并传输较小的(1-2k字节)软件包。另外,在客户端接收1Mb数据包也可以。
但是,当我尝试从客户端发送71k数据包时,连接立即关闭,而没有onerror事件和任何错误消息。我不明白那里发生了什么。你知道吗?
数据包56kbytes从客户端发送很好,所以我猜“错误”数据包的大小是64kbytes。我认为某处存在限制。
这是用于在浏览器端创建客户端的代码
var wsServer = new webSocketServer({
// WebSocket server is tied to a HTTP server. WebSocket request is just
// an enhanced HTTP request
httpServer: server,
//autoAcceptConnections: false
});
我做错了什么?
答案 0 :(得分:1)
我自己找到了解决方案。事实证明,发送到服务器的最大允许帧大小不是由浏览器设置的,而是由服务器本身设置的。就我而言,我需要使用以下代码增加此值(默认为65536):
var wsServer = new webSocketServer({
httpServer: server,
maxReceivedFrameSize: 2048000, // Added this line
maxReceivedMessageSize: 2048000, // And this line
});
因此,服务器的最大帧大小约为2Mbytes,对于我的应用程序来说已经足够了。