Are Cordova Chrome App(CCA) plugins compatible w/ Cordova/ionic app


#1

I have an ionic app that needs to make a TCP socket connection between it and a Wifi access point(no internet just a local access point).

The only library I could find for doing this from the client side was Chrome Sockets(Deprecated) and Chrome Sockets TCP

I was able to create the TCP socket, connect, send and receive with the deprecated version. But I always got the same string back in the response that I sent over the connection which was not the expected behavior.

When I moved to the supported Chrome Sockets TCP lib I could create the socket but not connect to it. I came across this CCA command line tool tutorial after seeing some Stack Overflow posts talking about a manifest.mobile.json file which I did not have in my ionic app.

I installed the CCA command line tool and ran through the tutorial to create a basic CCA app. I grabbed the generated manifest.mobile.json file from that and through it in the www folder of mine and tried to connect again with no better results. Here is the generated manifest.mobile.json file with a few lines I added based on ;

 {
  "packageId": "com.your.company.ChromeApp",
  // Android-only overrides here (e.g. icons, name, version)
  "android": {
  },
  // iOS-only overrides here (e.g. icons, name, version)
  "ios": {
  },
  // Uncomment to use system WebView rather than Crosswalk
   "webview": "system",

  // Uncomment to enable use of eval()
   "cspUnsafeEval": true,

  // Uncomment to enable use of inline <script>
   "cspUnsafeInline": true,

   "sockets": {
      "tcp": {"connect" : "*"}
   }
}

And this is the code used to make and connect to the tcp socket

 chrome.sockets.tcp.create(function(createInfo) {
            chrome.sockets.tcp.connect(createInfo.socketId, 'MY_IP', MY_PORT, function(result) {
              if (result === 0) {
                chrome.sockets.tcp.send(createInfo.socketId, PID, function(result) {
                  if (result.resultCode === 0) {
                    console.log('connectAndSend: success');
                    chrome.sockets.tcp.disconnect(createInfo.socketId);
                    chrome.sockets.tcp.close(createInfo.socketId);
                  }
                });
              }
            });
          });

And the error message I get

failed to connect to /MY_IP (port MY_PORT): connect failed: ENETUNREACH (Network is unreachable)
callbackWithError @ errors.js:30
fail @ sockets.tcp.js:68
cordova.callbackFromNative @ cordova.js:293
processMessage @ cordova.js:1079
processMessages @ cordova.js:1102

#2

I’m writing an App that need tcp and upd interface, I used this https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-sockets-tcp and this https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-sockets-upd

I’ve already tried the upd plugin that works right, I suppose that also the tcp works (I haven’t completed the tests for now).


#3

One more thing… The upd plugin only works on real device, probably for the tcp plugin is the same.


#4

Thanks. I can only use TCP for my use case. The TCP library you linked to is the one I’m trying to get working. Did you have to do anything with the CCA command line tool or the manifest.mobile.json file?


#5

Oh. and I’m testing on a real device as well.


#6

I haven’t touched manifest file… Are you sure that MY_IP accepts connection on MY_PORT? Maybe you can try with a port scan to check.


#7

I was able to connect to MY_IP with the deprecated version ,chrome.socket, passing in ‘tcp’ as a parameter. Just not using the now supported chrome.socket.tcp that you have linked to.


#8

I haven’t tried yet, I’ll write my results as soon as I finished the tests.
Meanwhile you can try a little stupid correction, instead of:

chrome.sockets.tcp.create(function(createInfo) {

you can try with:

chrome.sockets.tcp.create({}, function(createInfo) {

Ps. and use angular.bootstrap in deviceready event…


#9

That would have been awesome if it had worked. Unfortunately I got the same error. Looking forward to seeing your code.


#10

fabioferrero do you have some example code of configuring angular.bootstrap? I also saw here you tried to use the Blocshop sockets-for-cordova plugin. Did you have any success with it? I’m trying to use it but the app freezes like an infinite loop is running when it gets called.


#11

Very simple and fast example:

  • in the body tag don’t add ng-app=“your-app-name”, use only

  • add this code to the index.html:

This works for me, still writing these app, maybe I can post some demo code when finished… (is a commercial app).


#13

Ciao Fabio,

I am trying to use UDP on the ionic app v1.7.7.
I tried to install cordova-plugin-chrome-apps-sockets-upd but now I get
ionic $ An uncaught exception occurred and has been reported to Ionic
listen EADDRINUSE (CLI v1.7.7)

would you mind share the steps how you are installing and using the cordova-plugin-chrome-apps-sockets-udp

very appreciate,

Giorgio Francescangeli


#14

Strange… can you post a slice of your code?


#15

Have you tried this: https://github.com/nutella/ionic-cordova-chrome-udp-example ?


#16

Hello Fabio,
I actually tried to install the cordova plugin on my own app, and it broke the app.
Then I created one from your repo, installing the cordova “chrome-udp” plugin and it works,
I still have some challenges to send udp but I only spend an hour on it, got to do my homework :smiley:

thanks for sharing your example on github, very appreciated

Giorgio


#17

If you post some app’s code slice, maybe we can better help you…