自己找到原因: 我为PC端的微信打开的小程序和开发工具中的小程序使用了同样的端口号,同时它们的IP也相同,这就导致了后打开的小程序无法正常打开UDP连接 实际使用过程中每个手机打开的小程序端口号一样,但是IP不一样,不会出现这个问题
为什么发布后的小程序UDP通讯无法收到信息?在开发环境下调试可以实现UDP正常通讯,但是发布了的小程序在电脑和手机上都通讯没反应。 UDP里我使用的是固定端口号,发送地址为“255.255.255.255”进行广播发送。 [图片]
2021-01-07请教一下,为什么我的UDP程序在发布以后就不能正常通讯了?在调试状态下可以!
UDPSocket.onMessage IOS系统收不到硬件返回的消息,是什么原因?udpSocket.bind(8888) UDPSocket.onMessage IOS系统通过指定的硬件设备ip加端口能发送出去消息,硬件设备也能收到消息,但收不到硬件设备返回的消息,Andriod系统和硬件设备可以相互通讯,是什么原因 sendMessage(){ if (this.mydata.isSend){ return ; } const udpSocket = wx.createUDPSocket() this.mydata.isSend = true const that = this; let ip = this.mydata.remoteUrl.ip let port = this.mydata.remoteUrl.port let message = this.mydata.message if(message.trim() === ''){ wx.showToast({ title: '请输入内容', }) return ; } udpSocket.bind() udpSocket.send({ address: '192.168.4.1', port:'1000', message: message, }) this.mydata.isSend = false let list = this.data.messageList let obj = { text: message, from : 2 } list.push(obj) this.setData({ messageList : list }) }, onLoad: function (options) { var that = this; this.initUdpSocket() that.getConnectedWifi(); }, initUdpSocket(){ const udpSocket = wx.createUDPSocket(); if(udpSocket === null){ console.log('暂不支持') return ; } udpSocket.bind(8888) udpSocket.onListening(function(res){ console.log('监听中...') console.log(res) }) udpSocket.onMessage(function (res) { console.log('ddddd',res) }) },
2021-01-07/*UDP调试助手里发的是GBK编码,但是小程序里使用的是UTF-8解码,所以会出现乱码*/ 更改为发送UTF-8编码的数据,问题解决
udp怎样将获取的字节数组转中文字符?udp_Receive:function (res){ if (res.remoteInfo.size > 0) { let unit8Arr = new Uint8Array(res.message); let encodedString = String.fromCharCode.apply(null, unit8Arr), decodedString = decodeURIComponent(escape((encodedString)));//没有这一步中文会乱码 console.log('message:'+decodedString); } }, 按照这个代码调试会报错 [图片]
2021-01-06