用户环境(iphone8)无法建立wss socket连接?
发布于 5 年前 作者 gaoyang 3358 次浏览 来自 官方Issues

提示是wsssocket数量超限:fail wcwss exceed max concurrent count

机型iphone8, 微信版本7.0.5,

代码片段还不清楚怎么弄。

目前就是遇到onSocketError时会关闭socket,然后执行重新连接

wx.onSocketError((res) => {

console.log(‘WebSocket连接打开失败’, res)

util.setInitStepTrue(1)

util.hideLoading()

this.wsDisconnect()

this.reconnect()

})

wx.onSocketClose((res) => {

console.log(‘WebSocket 已关闭!’, res)

util.setInitStepTrue(1)

util.hideLoading()

this.reconnect()

})

wx.onSocketOpen((res) => {

console.log(‘WebSocket连接打开’, res)

util.setInitStepTrue(1)

util.hideLoading()

clearInterval(this.reconnectTimer)

this.reconnectTimer = 0

this.heartCheck.reset().start()

})

reconnect() {

if (this.reconnectTimer > 0) {

console.log(“上次reconnect定时器还在进行”)

return;

}

clearInterval(this.reconnectTimer)

this.reconnectTimer = 0

this.reconnectTimer = setInterval(() => {

console.log(“do reconnect”)

this.wsConn()

}, 1000);

},

wsConn() {

let _this = this

util.costTimeStart();

return new Promise((resolve,reject) =>{

if (_this.wssSocketTask) {

_this.wssSocketTask.close({

complete: res => {

console.log(“旧连接关闭结果”, res)

_this.wssSocketTask = wx.connectSocket({

url: getApp().globalData.wsUrl,

header: {

‘cookie’: ‘token=’ + getApp().globalData.token

},

success(res) {

util.costTimeEnd(“WebSocket连接成功耗时”)

console.log(“wx.connectSocket res”, res)

resolve(0);

},

})

console.log(“新连接”, _this.wssSocketTask)

}

})

} else {

_this.wssSocketTask = wx.connectSocket({

url: getApp().globalData.wsUrl,

header: {

‘cookie’: ‘token=’ + getApp().globalData.token

},

success(res) {

util.costTimeEnd(“WebSocket连接成功耗时”)

console.log(“wx.connectSocket res”, res)

resolve(0);

},

})

console.log(“新连接”, _this.wssSocketTask)

}

})

},

wsDisconnect(){

return new Promise((resolve, reject) => {

wx.closeSocket({

reason: “Close before reconnect”,

complete: res => {

console.log(“Close before reconnect, 结果是”, res)

resolve(0)

}

})

})

},

回到顶部