Chrome Sockets Tcp

Hi Guys,

i have a problem with the chrome.sockets.tcp plugin.

I´m always getting the error “Uncaught InvalidCharacterError: ‘atob’ failed: The string to be decoded is not correctly encoded. cordova.js:311
cordova.callbackFromNative cordova.js:311
(anonymous function)” when receiving data from the server.

Here is my code;

  connect() {
    console.log("pressed");
    (<any>window).chrome.sockets.tcp.create({}, createInfo => {
      this.socketTcpId = createInfo.socketId;
      console.log(createInfo);
      (<any>window).chrome.sockets.tcp.setPaused(this.socketTcpId, false );
      (<any>window).chrome.sockets.tcp.onReceive.addListener( info => { //callback function with info as the parameter
        console.log(info);
        console.log("test");
      });
      (<any>window).chrome.sockets.tcp.onReceiveError.addListener( info => {
        console.log(info);
        console.log("mooo");

      });
      (<any>window).chrome.sockets.tcp.connect(this.socketTcpId, "192.168.2.202", 5555, result => {
        console.log("Connected to server");
      },error => {
        console.log(error);
      });
    });
  }

The send method works perfectly.

	send(){

				var data2send= this.str2arrayBuffer( "Message Message Message\n\r");
				// connection ok, send the packet
				(<any>window).chrome.sockets.tcp.send(this.socketTcpId, data2send);

	}

Has anyone an idea what i´m doing wrong?

Hi. I have this problem. with te same code that you have, it never pass throw chrome.sockets.tcp.create. (no errors report)

I program logData to show on screen, but the last it shows is “pressed”

Any ideas ?

Here is my code:

  createSocket(ipAddr,ipPort) {
    console.debug("pressed");
    this.logData.push("pressed");
    (<any>window).chrome.sockets.tcp.create({}, createInfo => {
      this.socketTcpId = createInfo.socketId;
      console.debug(createInfo);
      this.logData.push("created");
      (<any>window).chrome.sockets.tcp.setPaused(this.socketTcpId, false );
      (<any>window).chrome.sockets.tcp.onReceive.addListener( info => { //callback function with info as the parameter
        console.debug(info);
        this.logData.push("test");
      });
      (<any>window).chrome.sockets.tcp.onReceiveError.addListener( info => {
        console.debug(info);
        this.logData.push("mooo");

      });
      (<any>window).chrome.sockets.tcp.connect(this.socketTcpId, ipAddr, ipPort, result => {
        this.logData.push("Connected to server");
      },error => {
        console.debug(error);
      });
    });
    this.logData.push("end create socket");
        /*
        (<any>window).chrome.sockets.tcp.onReceive.addListener( info => { //callback function with info as the parameter
          var data= this.arrayBuffer2str(info.data);
          //this.frameReceived.emit(data);
          alert(data);
        });
        */
  }