小程序 websocket 关闭失败
- js ( 项目里的不行,我提出来了个简单的小 demo )
open () {
this.socketTask = wx.connectSocket({
url: `ws://follow-up.bjbryy.cn:xxxxx`,
success: res => {
console.log('----- socket create -----')
}
})
this.socketTask.onOpen(onOpen => {
// this._socketOpen = true
console.log('----- socket 连接打开 -----')
})
this.socketTask.onClose(res => {
console.log('res--------------------> ', res)
})
},
close () {
this.socketTask.close()
}
<button bindtap="open">打开</button>
<button bindtap="close">关闭</button>

正常的关闭应该是 code 为 1000,但是我就是正常关闭,监控却是 1006 非正常关闭,求指导~~
在小程序中使用websocket,可以试试【GoEasy】这款websocket框架,原生支持心跳、断网重连等,接口也很简单,使用起来没什么难度的。