小程序socket 个别提示未能完成操作 连接被对方重置
场景:
我们做了一个答题的小程序
答题是通过socket来实现的
wx.connectSocket({ url: url, header: { 'content-type': 'application/json' } }) wx.onSocketOpen((res) => { this.isOpen = true; console.log('WebSocket连接已打开!', res) }) wx.onSocketError((res) => { this.isOpen = false; // this.closeType = 0; console.log('WebSocket连接打开失败,请检查!', res) if (this.closeType == 0 && this.options.onClose) { // this.options.onClose(this.closeType); } this.closeType = 0; }) wx.onSocketMessage((res) => { this.options.onMsg(JSON.parse(res.data)); console.log('收到服务器内容:', res.data) }) wx.onSocketClose((res) => { this.isOpen = false; if (this.options.onClose) { this.options.onClose(this.closeType); } this.closeType = 0; console.log('WebSocket 已关闭!') }) |
在执行wx.closeSocket()时 有个别手机接收不到wx.onSocketClose()事件,而是直接执行wx.onSocketError,
同时这个错误附带的错误提示是:“个别提示未能完成操作 连接被对方重置”
