tony伟
tony伟
  • 发布:2020-11-20 18:13
  • 更新:2020-11-21 11:23
  • 阅读:545

安卓WebSocket无法正常open

分类:HTML5+
h5+

各位大神,小弟有急事请教。
我用的是HBuilderX打包的安卓APP H5跳转到http://一个连接上。
这个连接使用了WebSocket 在电脑GOOGLE和手机浏览器(华为)WebSocket都正常可以OPEN到数据。
但是HBuilderX打包 跳转到一个连接上 WebSocket 没有任何反映呀

急急急

我的代码 大神帮我看看

let hburl = 'wss://api.weburl/ws';

let requestK = { // 请求对应信息的数据
req: "<?php echo $market[$_GET['cointwo']]['curl'];?>",
id: "<?php echo $market[$_GET['cointwo']]['name'];?>",
from: Math.round(new Date().getTime()/1000) - 60,
to: Math.round(new Date().getTime()/1000)
};

let subK = { // 订阅数据
sub: "<?php echo $market[$_GET['cointwo']]['curl'];?>",
id: "<?php echo $market[$_GET['cointwo']]['name'];?>"
};

let socketK = new WebSocket(hburl);
socketK.onopen = function () {
console.log("connection establish");
socketK.send(JSON.stringify(subK));
//socketK.send(JSON.stringify(requestK));
};
socketK.onmessage = function (event) {
let blob = event.data;
let reader = new FileReader();
reader.onload = function (e) {
let ploydata = new Uint8Array(e.target.result);
let msg = pako.inflate(ploydata, {to: 'string'});
handleData(msg);
};
reader.readAsArrayBuffer(blob, "utf-8");
};
socketK.onclose = function () {
console.log('connection closed');
setInterval("socketK", 2000);
};

// 处理接收到的信息
function handleData(msg) {
let data = JSON.parse(msg);
if (data.ping) {
// 如果是 ping 消息
sendHeartMessage(data.ping);
} else if (data.status === 'ok') {
// 响应数据
handleReponseData(data);
} else {
// 数据体
coindata(data);
}
}

// 发送响应信息
function sendHeartMessage(ping) {
socketK.send(JSON.stringify({"pong": ping}));
}

function handleReponseData(data) {
}

2020-11-20 18:13 负责人:无 分享
已邀请:
tony伟

tony伟 (作者)

有人帮帮我吗?

tony伟

tony伟 (作者)

刚测试了一下 WebSocket 直接就onclose 了 没有open啊

tony伟

tony伟 (作者)

错误代码返回1006

该问题目前已经被锁定, 无法添加新回复