我正在使用bonjour为我的服务器上运行的服务提供服务
var test= bonjour.publish({ name: "abcd", type: 'http', port: settings.server.port });
test.start();在客户端上运行:
function onDeviceReady() {
console.log('in deviceready')
var zeroconf = cordova.plugins.zeroconf;
console.log(zeroconf)
zeroconf.watch('abcd._http._tcp.local.', function (result) {
console.log('in zeroconf')
var action = result.action;
var service = result.service;
if (action == 'added') {
console.log('service added', service);
} else {
console.log('service removed', service);
}
});
console.log("test")
}但是我的zeroconf.watch方法没有得到任何响应/成功。我添加了所需的插件,但都不起作用……
发布于 2016-04-03 00:58:58
我为我自己工作:
<script type="text/javascript">
function onDeviceReady() {
ZeroConf.watch('_http._tcp.local.', function(resp){
document.getElementById("zeroconf2").innerHTML = resp;
});
}
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
onLoad();
</script>并将这一行放到config.xml
<gap:plugin name="cordova-zeroconf-plugin" source="npm" />https://stackoverflow.com/questions/35157576
复制相似问题