小程序 websocket 关闭失败
发布于 4 年前 作者 jing37 10576 次浏览 来自 问答

👉 js ( 项目里的不行,我提出来了个简单的小 demo )

open () {
 
   this.socketTask = wx.connectSocket({
 
     url: `ws://xxx.xxx.xxx: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()
 
 }

👉 wxml

<button bindtap="open">打开</button>    
 
<button bindtap="close">关闭</button>

👉 打印信息

👉!!!正常的关闭应该是 code 为 1000,但是我就是正常关闭,监控却是 1006 非正常关闭,求指导~~

2 回复

看起来像是缺少心跳包的实现?

麻烦提供一下出现问题的机型和微信版本,并且给个相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

回到顶部