SuperMonster003 / AutoJs6

安卓平台 JavaScript 自动化工具 (Auto.js 二次开发项目)
https://docs.autojs6.com
Mozilla Public License 2.0
2.16k stars 653 forks source link

ws .on(WebSocket.EVENT_OPEN,····) 不起作用 #218

Open Muzphy opened 5 months ago

Muzphy commented 5 months ago
var websocketUrl = "ws://172.29.240.1:8111/websocket/message";
var ws = null;
var uniqueId = null;

run();
console.setExitOnClose(7e3).show();
function run() {
    try {
        if (ws == null) {
            init();
            ws = new WebSocket(websocketUrl);
            ws.send(JSON.stringify({ "binding": uniqueId }));
        }
        sleep(1000);
    } catch (e) {
        console.log(e);
    }
}

ws.on(WebSocket.EVENT_OPEN, (res, ws) => {
    console.log('open');
    console.log(res);
})
ws.on(WebSocket.EVENT_MESSAGE, (message, ws) => {
    console.log('message');
})

代码大致是这样,运行结果是ws可以连接,但是直接打印message而没有打印open 不是很明白为什么ws open的事件没进去 纯纯的新手,希望大家可以不吝赐教 thx