websocket通信1009错误,
问题说明:
springboot继承 WebSocketConfigurer实现websocket通信服务,服务器端报错,“The decoded text message was too big for the output buffer and the endpoint does not support partial messages”,浏览器端显⽰服务器上的该次会话已经关闭。1009错误,内容长度超限。问题解决
在应⽤启动类中通过注解注⼊⽅式设置通信的⽂本和⼆进制消息的⼤⼩。
import org.springframework.beans.factory.annotation.Autowired;
import t.annotation.Bean;
import t.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.urrent.ThreadPoolTaskScheduler;
import org.springframework.fig.annotation.EnableWebSocket;
import org.springframework.fig.annotation.WebSocketConfigurer;
import org.springframework.fig.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
@Autowired
private MyHandler myHandler;
/**
* sockJs 低版本浏览器不⽀持webSocket时使⽤
* url结构:host:port/{endpoint}/{server-id}/{session-id}/websocket
* 也可以: ws://host:port/{endpoint}/websocket
* <p>
* 不使⽤sockJs 访问时 url: ws://host:port/{endpoint}
* <p>
* setClientLibraryUrl 兼容客户端sockJs版本
websocket和socket
*/
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(myHandler, "/myHandler").setAllowedOrigins("*");
registry.addHandler(myHandler, "/myHandler").setAllowedOrigins("*").withSockJS()
.setTaskScheduler(sockJsScheduler()).setClientLibraryUrl("//cdn.jsdelivr/sockjs/1/sockjs.min.js");
}
@Bean
public ServletServerContainerFactoryBean createWebSocketContainer() {
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
// ws 传输数据的时候,数据过⼤有时候会接收不到,所以在此处设置bufferSize
container.setMaxTextMessageBufferSize(512000);
container.setMaxBinaryMessageBufferSize(512000);
container.setMaxSessionIdleTimeout(15 * 60000L);
return container;
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。