17:03:10.231 closeSocket:fail WebSocket is not connected
17:03:10.254 WebSocket连接打开失败,请检查! at App.vue:61
connectSocket() {
uni.connectSocket({
url: 'wss://localhost:8888/websocket',
header: {
'content-type': 'application/json'
},
});
}
adb 端口为5555
onLaunch: async function() {
service.Cache.jwt = await service.getJwt();
if (service.Cache.jwt) {
this.login(service.Cache.jwt);
}
if (this.hasLogin) {
this.$ImMessageProtocol.type = 2;
this.$ImMessageProtocol.jwt = await service.getJwt();
var loginStr = JSON.stringify(this.$ImMessageProtocol);
var socketStatus = false;
var t2 = setInterval(function() {
uni.sendSocketMessage({
data: loginStr,
fail: function() {
uni.showToast({
icon: 'none',
title: '发送失败'
});
},
});
}, 1000 1000);
var me = this;
uni.onSocketOpen(function(res) {
console.log('WebSocket连接已打开!');
clearInterval(t2); //去掉定时器
t2 = setInterval(function() {
uni.sendSocketMessage({
data: loginStr,
fail: function() {
uni.showToast({
icon: 'none',
title: '发送失败'
});
},
});
}, 30 1000);
});
uni.onSocketError(function(res) {
console.log('WebSocket连接打开失败,请检查!');
uni.closeSocket();
me.connectSocket();
});
uni.onSocketClose(function(res) {
console.log('WebSocket 已关闭!');
me.connectSocket();
});
this.connectSocket();
}