uts android 插件中(uni_modules/uts-udp/utssdk/app-android/index.uts)
import MulticastSocket from 'java.net.MulticastSocket'
....
export class UDPMulticast {
private group: string
private port: Int
private socket: MulticastSocket | null = null
private isListener = false
constructor(group: string, port: Int) {
this.group = group;
this.port = port;
}
listener(receive:(msg:string)=>void){
this.socket = new MulticastSocket(this.port);
console.log('this.socket',this.socket);// -----这里有疑问
....
receive('hhh')
}
}
vue页面中(pages/index/index.vue)
import { UDPMulticast } from '../../uni_modules/uts-udp'
export default {
methods:{
initUdp(){
this.server = new UDPMulticast(MULTICAST_IP, MULTICAST_PORT)
this.server.listener((res) => {
console.log("res",res);
})
}
}
}
1***@qq.com (作者)
我重新测试了,确实不是new MulticastSocket() 的值差异的问题;
我最终的问题是我卡在了回调函数的调用上,同样的代码在3.8.7, 不会返回信息到vue回调函数中,3.7.11则可以;代码我将附在下发回复中,请帮忙看看
2023-08-15 14:53