@1024042400 写道:
代码是官方示例代码
let ws = new WebSocket("ws://echo.websocket.org");
ws.onopen = function (event) {
console.log("Send Text WS was opened.");
};
ws.onmessage = function (event) {
console.log("response text msg: " + event.data);
};
ws.onerror = function (event) {
console.log("Send Text fired an error");
};
ws.onclose = function (event) {
console.log("WebSocket instance closed.");
};有的机型例如红米Note7, 切后台几秒后, 触发了onclose方法, 如果再执行一次上面的代码则触发onerror方法, 控制台输出Send Text fired an error.
帖子: 1
参与者: 1