socket 调试

This commit is contained in:
xyf-mac
2021-11-09 17:40:46 +08:00
parent e3215376df
commit 24f778de84
8 changed files with 12123 additions and 0 deletions

32
electron-app/test/cmd.js Normal file
View File

@@ -0,0 +1,32 @@
// 游戏的inspect脚本
const host = "192.168.1.5";//"localhost";
const port = 1109;
let url = `ws://${host}:${port}`;
const ws = new WebSocket(url);
ws.onopen = () => {
console.log("成功链接调试服务器", url);
};
ws.onmessage = (event) => {
console.log("收到消息", event);
const {code} = JSON.parse(event.data);
if (code) {
let ret = null;
let error = false;
try {
ret = eval(`${code}`);
} catch (e) {
error = true;
ret = e.toString();
}
ws.send(JSON.stringify({
error,
data: ret,
}));
}
};
ws.onerror = () => {
console.log("error");
};
ws.onclose = () => {
console.log("close");
};

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="cmd.js"></script>
</head>
<body>
</body>
</html>