Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Muzphy opened this issue Jan 17, 2024 · 0 comments
Open

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

Muzphy opened this issue Jan 17, 2024 · 0 comments

Comments

@Muzphy
Copy link

Muzphy commented Jan 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant