Skip to content

Commit

Permalink
Add onerror handler for websocket connections for connect4 and reversi
Browse files Browse the repository at this point in the history
  • Loading branch information
UNIDY2002 authored Feb 4, 2024
1 parent 0635a6d commit e0f704b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions connect4/player.html
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,10 @@
websocket.onopen = function (event) {
console.log("judger connected");
}

websocket.onerror = function (event) {
alert("与评测机连接失败,请刷新网页。");
}
// 1.

// 2.连接到评测器后收到消息
Expand Down Expand Up @@ -562,6 +566,10 @@
request: "connect"
}))
}

websocket.onerror = function (event) {
alert("与评测机连接失败,请刷新网页。");
}
// 1.

// 2.连接到评测器后收到消息
Expand Down
12 changes: 12 additions & 0 deletions reversi/player.html
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@
let msg = {token:token,request:"connect"};
ws.send(JSON.stringify(msg));
};

ws.onerror = function (evt) {
alert("与评测机连接失败,请刷新网页。");
}

//【用于指定收到服务器数据后的回调函数】
//【服务器数据有可能是文本,也有可能是二进制数据,需要判断】
Expand Down Expand Up @@ -333,6 +337,10 @@
let msg = {token:token_b64,request:"connect"};
ws.send(JSON.stringify(msg));
};

ws.onerror = function (evt) {
alert("与评测机连接失败,请刷新网页。");
}

//【用于指定收到服务器数据后的回调函数】
//【服务器数据有可能是文本,也有可能是二进制数据,需要判断】
Expand Down Expand Up @@ -360,6 +368,10 @@
console.log("Connection open...");
};

ws.onerror = function (evt) {
alert("与评测机连接失败,请刷新网页。");
}

//【用于指定收到服务器数据后的回调函数】
//【服务器数据有可能是文本,也有可能是二进制数据,需要判断】
ws.onmessage = function (event) {
Expand Down

0 comments on commit e0f704b

Please sign in to comment.