【发布时间】:2016-10-20 04:13:38
【问题描述】:
我的 SockJs 客户端在网页中,发送帧大小为 16K 的消息。消息大小限制决定了我可以传输的文件的最大大小。
以下是我在文档中找到的内容。
/**
* Configure the maximum size for an incoming sub-protocol message.
* For example a STOMP message may be received as multiple WebSocket messages
* or multiple HTTP POST requests when SockJS fallback options are in use.
*
* <p>In theory a WebSocket message can be almost unlimited in size.
* In practice WebSocket servers impose limits on incoming message size.
* STOMP clients for example tend to split large messages around 16K
* boundaries. Therefore a server must be able to buffer partial content
* and decode when enough data is received. Use this property to configure
* the max size of the buffer to use.
*
* <p>The default value is 64K (i.e. 64 * 1024).
*
* <p><strong>NOTE</strong> that the current version 1.2 of the STOMP spec
* does not specifically discuss how to send STOMP messages over WebSocket.
* Version 2 of the spec will but in the mean time existing client libraries
* have already established a practice that servers must handle.
*/
public WebSocketTransportRegistration setMessageSizeLimit(int messageSizeLimit) {
this.messageSizeLimit = messageSizeLimit;
return this;
}
我的问题: 我可以设置部分消息传递,以便文件部分传输,而不是像现在那样作为单个消息传输吗?
更新: 仍在寻找带有部分消息传递的解决方案 同时,现在使用 HTTP 处理大型消息(即我的应用程序中的文件上传/下载)。
【问题讨论】:
-
我已经登陆这里,因为我自己正在尝试这个。我有您正在寻找的解决方案,但在服务器端我不想接收部分,而是要接收流(仍然是部分接收,但使用内部缓冲区)想知道您是否找到了更好的解决方案或至少需要那个解决方案。
-
我现在切换到 HTTP 只是为了传输文件,所以如果你有一个通过 websockets 的 stream 解决方案,那就太好了..
-
我已经发布了答案,虽然我的直接动机是减少在我的单页应用程序上上传大文件的内存峰值,这在测量上满足我的要求,但我链接的实验项目充其量是原始的,它是只是一个 PoC。
标签: java spring stomp spring-websocket sockjs