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?