【问题标题】:ionic 4 - cordova-plugin-chrome-apps-sockets-udp离子 4-cordova-plugin-chrome-apps-sockets-udp
【发布时间】:2020-05-01 10:08:33
【问题描述】:

我正在尝试为 android 和 ios 构建一个 ionic 应用程序。 在这个应用程序中,我需要向服务器发送和接收 udp 数据包。 为此,我尝试使用https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-sockets-udp

但我在真实设备 android 设备上运行时不断收到此错误:

core.js:9110 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'bind' of undefined
TypeError: Cannot read property 'bind' of undefined 

导致此错误的代码是:

async broadcasting(messageSend)
{

    this.platform.ready().then(
        (readySource) => {
    var udp = require('udp-packet');
    chrome = window['chrome'];
    if(readySource == 'cordova')
    {
      const pack = udp.encode({
        sourceIp: '10.0.0.1',
        sourcePort: 58936,
        destinationIp: '85.214.60.74',
        destinationPort: 7810,
        data: new Buffer(messageSend)
      });

      (<any>window).chrome.sockets.udp.bind(123445, pack,'85.214.60.74',7810, function(result){
        console.log("result bind",result);
      });
      chrome.sockets.udp.send(123445, pack,'85.214.60.74',7810, function(result){
        console.log("result send",result);
      });
      chrome.sockets.udp.onReceive.addListener(function(result){
        console.log("result listener",result);
      });
    }
        });
}

知道我做错了什么吗?

【问题讨论】:

    标签: angular ionic-framework udp cordova-plugins ionic4


    【解决方案1】:

    我最终发现我只安装了 tcp 插件,我必须运行“cordova plugin add cordova-plugin-chrome-apps-sockets-udp”才能使其工作。

    【讨论】:

      猜你喜欢
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-02
      • 2019-01-15
      • 2020-10-17
      相关资源
      最近更新 更多