java.io.EOFException at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer

如題,網上找了相關資料查明是websocket鏈接超時的問題。使用了反向代理,所以超過60S沒有數據傳輸的鏈接會斷開。html

把代理的那個超時時間設置長一點,無限長。你開什麼玩笑!那還代理個啥玩意。前端

解決方法一:後臺寫個定時程序每<60s頻率給前端的socket發個消息就行了。java

import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import javax.annotation.Resource; /** * @Auther: lanhaifeng * @Date: 2019/5/16 0016 14:29 * @Description:webSocket定時發送消息類 * @statement: 以<60s的頻率發送給websocket鏈接的對象,以防止反向代理的60s超時限制 */ @Configuration //1.主要用於標記配置類,兼備Component的效果。
@EnableScheduling   // 2.開啓定時任務
public class SaticScheduleTask { @Resource private WebSocketServer webSocketServer; //3.添加定時任務 //@Scheduled(cron = "0/5 * * * * ?") //或直接指定時間間隔,例如:5秒
    @Scheduled(fixedRate=58*1000) private void configureTasks() throws Exception{ webSocketServer.sendMessage("鏈接成功"); } }
前提是你的websocket是多線程模式,不然多個socket鏈接會由於一個session的問題報錯。參考spring boot集成Websocket
相關文章
相關標籤/搜索