无法使用Android Corova-zeroconf-plugin与具有.local域的设备进行通信 [英] Unable to communicate to device with .local domain using android, corova-zeroconf-plugin

查看:111
本文介绍了无法使用Android Corova-zeroconf-plugin与具有.local域的设备进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在我的网络中投放广告的iot设备,名称为iotdevice.local,安装Bonjour之后,我能够在Windows pc中向该域发送http请求.但是我正在开发一个离子应用程序,因此我将经常与该设备进行通讯. 所以我正在使用cordova-zeroconf-plugin. ( https://www.npmjs.com/package/cordova-plugin-zeroconf). 当我添加监视.local服务时,我正在查看服务.但是当我在$ http函数中使用iotdevice.local时,我的请求很容易. 我有这个代码 App.js

I am having an iot device which is advertising in my network with name iotdevice.local, i am able to send http requests to this domain in my windows pc after installing Bonjour. But i am developing an ionic app from which i'll be communicating frequently with this device. So i am using cordova-zeroconf-plugin. (https://www.npmjs.com/package/cordova-plugin-zeroconf). I am seeing the services when i add watch for .local services. but my requestis faield when i use iotdevice.local in $http function. I have this code App.js

if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  cordova.plugins.Keyboard.disableScroll(true);
  console.log("device ready");
  var zeroconf = cordova.plugins.zeroconf;
  zeroconf.watch('_http._tcp.local.', function(result) {
    var action = result.action;
    var service = result.service;
    console.log(JSON.stringify(result));
    if (action == 'added') {
        console.log('service added', service);
    } else {
        console.log('service removed', service);
    }
  });


}

它工作正常,并且在日志中我可以看到我的设备

It works fine and in logs i see my device

{操作":添加",服务":{应用程序":"http",域":本地",端口":80,名称":"iotdevice",服务器" :"iotdevice.local.",描述":"\ 00",协议":"tcp","qualifiedname":"iotdevice._http._tcp.local.",类型":"_ http._tcp.local .," txtRecord:{},"地址:[" 192.168.0.4]," urls:[" http ://192.168.0.4:80 ]}}

但是当我在 controller.js -

$scope.sendRequest2 = function(){
    $http({
      method: 'GET',
      url: 'http://iotdevice.local/events?id=600194067eba&action=socket1off'
    }).then(function successCallback(response) {
        $scope.req2succes=true;
        console.log("Sent");
      }, function errorCallback(response) {
        console.log(JSON.stringify(response));
        console.log("Could not Sent");
        $scope.req2succes=false;
      });
  }

它不起作用.请求状态始终为-1. 谁能帮助我,我该如何与他打交道.我从根本上做错了吗?

It Doesn't work. Request status is always -1. can anyone help me how i can deal with his. Am i doing something fundamentally wrong ?

推荐答案

使用IP地址代替http://iotdevice.local..使用http://192.168.0.4:80.希望这行得通.

Use IP address instead of http://iotdevice.local..Use http://192.168.0.4:80.Hope this works.

这篇关于无法使用Android Corova-zeroconf-plugin与具有.local域的设备进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆