yxw 2023-12-01 11:47:42 +08:00
parent 3a87d8f607
commit 2fad9b19fa
1 changed files with 5 additions and 0 deletions

View File

@ -62,6 +62,11 @@ $(function () {
ws.onclose = function (e) { ws.onclose = function (e) {
//当客户端收到服务端发送的关闭连接请求时触发onclose事件 //当客户端收到服务端发送的关闭连接请求时触发onclose事件
console.log("websocket已断开"); console.log("websocket已断开");
setTimeout(() => {
console.log('重新连接')
// 重新连接 WebSocket
createWebSocket();
}, 3000);
} }
ws.onerror = function (e) { ws.onerror = function (e) {
//如果出现连接、处理、接收、发送数据失败的时候触发onerror事件 //如果出现连接、处理、接收、发送数据失败的时候触发onerror事件