如题,网上找了相关资料查明是websocket连接超时的问题。使用了反向代理,因此超过60S没有数据传输的连接会断开。
把代理的那个超时时间设置长一点,无限长。你开什么玩笑!那还代理个啥玩意。
解决方法一:后台写个定时程序每<60s频率给前端的socket发个消息就好了。
1import org.springframework.context.annotation.Configuration; 2import org.springframework.scheduling.annotation.EnableScheduling; 3import org.springframework.scheduling.annotation.Scheduled; 4import javax.annotation.Resource; 5 6/** 7 * @Auther: lanhaifeng 8 * @Date: 2019/5/16 0016 14:29 9 * @Description:webSocket定时发送消息类 10 * @statement: 以<60s的频率发送给websocket连接的对象,以防止反向代理的60s超时限制 11 */ 12@Configuration //1.主要用于标记配置类,兼备Component的效果。 13@EnableScheduling // 2.开启定时任务 14public class SaticScheduleTask { 15 16 @Resource 17 private WebSocketServer webSocketServer; 18 19 20 //3.添加定时任务 21 //@Scheduled(cron = "0/5 * * * * ?") 22 //或直接指定时间间隔,例如:5秒 23 @Scheduled(fixedRate=58*1000) 24 private void configureTasks() throws Exception{ 25 webSocketServer.sendMessage("连接成功"); 26 } 27} 28 29前提是你的websocket是多线程模式,否则多个socket连接会因为一个session的问题报错。参考spring boot集成Websocket