From e0f704b6fbfa00352dc3ce0dace55927a4124b24 Mon Sep 17 00:00:00 2001 From: Xun Sun Date: Sun, 4 Feb 2024 12:14:34 +0800 Subject: [PATCH] Add onerror handler for websocket connections for connect4 and reversi --- connect4/player.html | 8 ++++++++ reversi/player.html | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/connect4/player.html b/connect4/player.html index 74f8ec8..4ff0dc8 100644 --- a/connect4/player.html +++ b/connect4/player.html @@ -531,6 +531,10 @@ websocket.onopen = function (event) { console.log("judger connected"); } + + websocket.onerror = function (event) { + alert("与评测机连接失败,请刷新网页。"); + } // 1. // 2.连接到评测器后收到消息 @@ -562,6 +566,10 @@ request: "connect" })) } + + websocket.onerror = function (event) { + alert("与评测机连接失败,请刷新网页。"); + } // 1. // 2.连接到评测器后收到消息 diff --git a/reversi/player.html b/reversi/player.html index 766a73d..06ff241 100644 --- a/reversi/player.html +++ b/reversi/player.html @@ -226,6 +226,10 @@ let msg = {token:token,request:"connect"}; ws.send(JSON.stringify(msg)); }; + + ws.onerror = function (evt) { + alert("与评测机连接失败,请刷新网页。"); + } //【用于指定收到服务器数据后的回调函数】 //【服务器数据有可能是文本,也有可能是二进制数据,需要判断】 @@ -333,6 +337,10 @@ let msg = {token:token_b64,request:"connect"}; ws.send(JSON.stringify(msg)); }; + + ws.onerror = function (evt) { + alert("与评测机连接失败,请刷新网页。"); + } //【用于指定收到服务器数据后的回调函数】 //【服务器数据有可能是文本,也有可能是二进制数据,需要判断】 @@ -360,6 +368,10 @@ console.log("Connection open..."); }; + ws.onerror = function (evt) { + alert("与评测机连接失败,请刷新网页。"); + } + //【用于指定收到服务器数据后的回调函数】 //【服务器数据有可能是文本,也有可能是二进制数据,需要判断】 ws.onmessage = function (event) {