Cannot get blocshop TCP sockets-for-cordova to work


#1

Need to have an Ionic mobile app connect to a Java Tomcat application server using TCP sockets. Have done the following:

  1. Per the blocshop site (https://github.com/blocshop/sockets-for-cordova) directions installed the plugin with: cordova plugin add cz.blocshop.socketsforcordova

  2. Added script src=“socket.js” below script src=“cordova.js” in the index.html file.

  3. When run in a debug mode in WebStorm the construct var socket = new Socket(); results in the error: ReferenceError: Socket is not defined

Any assistance on how to get blocshop TCP sockets-for-cordova to work in an Ionic project is welcomed.


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

Did initialize socket (var socket = new Socket()) after deviceready event is called?


#3

I am having the same problem TCP sockets-for-cordova in webstorm, calling it after device ready doesn’t work for me. Did you get it to work. Please assist.


#4

Hello,
For me it’s work but it’s really slow… install cordova plugin like:
cordova plugin add cz.blocshop.socketsforcordova
or cordova plugin add https://github.com/blocshop/sockets-for-cordova
and in your method you can make

let IP = "192.168.1.50";
let Port = 1234
let socket = new (<any>window).Socket();
        socket.open(IP, Port,
            function() {
                console.log('socket open');
                var dataString = "Printer is workly ! Printer is workly ! Printer is workly ! Printer is workly !";
                var data = new Uint8Array(dataString.length);
                for (var i = 0; i < data.length; i++) {
                  data[i] = dataString.charCodeAt(i);
                }
                console.log('before write');
                socket.write(data);
                console.log('after write');

                socket.shutdownWrite();

            },
            function(errorMessage) {
            // invoked after unsuccessful opening of socket
        });