离子4-cordova-plugin-chrome-apps-sockets-udp

问题描述 投票:0回答:1

我正在尝试为android和ios构建一个离子应用程序。在此应用中,我需要向服务器发送和接收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个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.