| | |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.web.socket.server.standard.ServerEndpointExporter; |
| | | import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean; |
| | | |
| | | @Configuration |
| | | public class WebSocketConfig { |
| | |
| | | public ServerEndpointExporter serverEndpointExporter() { |
| | | return new ServerEndpointExporter(); |
| | | } |
| | | |
| | | /** |
| | | * 修复 text_full 错误:增大 WebSocket 消息缓冲区 |
| | | */ |
| | | @Bean |
| | | public ServletServerContainerFactoryBean createWebSocketContainer() { |
| | | ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean(); |
| | | // 将文本消息缓冲区增大到 512KB (根据实际数据量调整,默认可能只有 8KB) |
| | | container.setMaxTextMessageBufferSize(512 * 1024); |
| | | // 二进制消息缓冲区同理 |
| | | container.setMaxBinaryMessageBufferSize(512 * 1024); |
| | | // 设置会话空闲超时时间 (可选) |
| | | container.setMaxSessionIdleTimeout(15 * 60 * 1000L); |
| | | return container; |
| | | } |
| | | } |
| | | |