用户主动断开后,再重连,onMessage消息重复出现
//TCP连接 按键
connectSocketFunciton() {
var that = this
var address = that.globalData.inputIP
var port=that.globalData.inputPort
console.log(address,port)
tcp.connect({
address:address,
port:port,
timeout:3,
})
tcp.onError((e)=>{
console.log(e)
let iszhuangtai=false
that.callzt(iszhuangtai)
wx.showToast({
title: "连接失败",
icon: 'none',
duration: 2000,//持续的时间
})
})
//TCP监听
tcp.onMessage((e)=>{
var util=require('pages/utils/util.js')
var that = this
var time= util.formatDate(new Date());
// console.log(e.message)
var jieshou= e.remoteInfo
var buffer = e.message;
var dataview = new DataView(buffer);
var ints = new Uint8Array(buffer.byteLength);
var str = '',ceshi='';
for (var i = 0; i < ints.length; i++) {
str+= String.fromCharCode(dataview.getUint8(i));
}
console.log("直接接受的消息,未处理",e)
console.log(str ,jieshou)
var shuju="@["+jieshou.address+"]-" +time+':\n'+ str
this.globalData.message=shuju
// if (this.onMessage) this.onMessage(shuju);
that.callback(shuju)
return str
})
},
//断开连接
tcpcloce(res){
var that =this
tcp.close()
//this.onMessage =null
// tcp.onMessage = null;
that.globalData.iszhuangtai = false
wx.showToast({
title: "连接断开",
icon: 'none',
duration: 2000,//持续的时间
})
},
问题已复现,我们会在后续版本中进行修复。