2

I want to develope basic extension. This extension should communicate on UDP. This extension is about messaging. I want to create a client. Because i create a server in Java. Client can sent message to server and server can message to client.

I look at Chrome Developer page. But these documents are not up to date. I create a basic client like this:

// values
var address     = null;
var connect     = null;
var disconnect  = null;

// UDP-Object
var echoClient  = null;

// -------------------------------------------------------------------------------------------------------------------

window.addEventListener("load", function() {

  // input: address.val
  address = document.getElementById("address");

  // button: connect.val
  connect = document.getElementById("connect");

  // button: disconnect.val
  disconnect = document.getElementById("disconnect");

  // button: connect.func
  connect.onclick = function(ev) {
    if(address.value != ""){
      echoClient = newEchoClient(address.value);
    }
  };

  // button: disconnect.func
  disconnect.onclick = function(ev) {
    echoClient.disconnect();
  }

  // send data
  setInterval(function(){ 
    echoClient.sender();
  }, 1000);

});

// -------------------------------------------------------------------------------------------------------------------

var newEchoClient = function(address) {
  var ec            = new chromeNetworking.clients.echoClient();
  ec.sender         = attachSend(ec);
  var hostnamePort  = address.split(":");
  var hostname      = hostnamePort[0];
  var port          = (hostnamePort[1] || 7) | 0;
  ec.connect(
    hostname, port,
    function() {
      console.log("Connected");
    }
  );
  return ec;
};

var attachSend = function(client) {
  var i = 1;
  return function(e) {
    var data = i;
    i++;
    client.echo(data, function() {
        console.debug(data.data); // the problem is here
    });
  };
};

But this code is not working. In the Chrome i took this error:

Error in event handler for sockets.udp.onReceive: RangeError: byte length of Uint32Array should be a multiple of 4
    at chrome-extension://boeaihphlidceiemkegklmbmefjgogfk/networking.js:84:25
    at chrome-extension://boeaihphlidceiemkegklmbmefjgogfk/networking.js:31:34

Where is wrong? What i do about this problem?

JSawyer
  • 23
  • 1
  • 4

1 Answers1

2

AFAIK, Chrome extension cannot use UPD for communication. As stated in this post, you can either use both an app and an extension that communicate, or use an extension and a Native Host.

I think only Chrome Apps have access to the socket API and not the Chrome extension also stated in this post.

You can also check this:

The references talks about chrome extension can't use chrome.socket.

Hope this helps.

Community
  • 1
  • 1
Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91