1、增加websocket保活

This commit is contained in:
weidong 2024-01-13 13:47:19 +08:00
parent 22894c69c8
commit b99ac8e11b
2 changed files with 4 additions and 3 deletions

View File

@ -38,7 +38,7 @@ public class WebSocketServer {
@OnMessage @OnMessage
public void onMessage(String msg, Session session){ public void onMessage(String msg, Session session){
log.info("websocket: "+msg); //log.info("websocket: "+msg);
} }
@OnError @OnError

View File

@ -157,13 +157,14 @@
layui.layer.alert("Open web socket failed!"); layui.layer.alert("Open web socket failed!");
} }
websocket.onclose = function (){ websocket.onclose = function (){
rxWin.append("websocket closed!\r\n"); rxWin.val("websocket closed!\r\n");
// 如果需要停止重复执行的定时任务 // 如果需要停止重复执行的定时任务
clearInterval(intervalId); clearInterval(intervalId);
} }
//接收信息 //接收信息
websocket.onmessage = function (event) { websocket.onmessage = function (event) {
rxWin.append(event.data + "\r\n"); console.log("event.data");
rxWin.val(rxWin.val()+event.data + "\r\n");
rxWin.scrollTop = rxWin.scrollHeight; rxWin.scrollTop = rxWin.scrollHeight;
} }