我想开发基本的扩展。这个扩展应该在UDP上进行通信。这个扩展是关于消息。我想创建一个客户端。因为我用Java创建了一个服务器。客户端可以向服务器发送消息,服务器可以向客户端发送消息谷歌浏览器扩展使用UDP
我看看Chrome Developer页面。但这些文件不是最新的。我创建了这样一个基本的客户端:
// 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
});
};
};
但是这段代码不起作用。在Chrome中,我发现了这个错误:
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
哪里出错?我对这个问题做了什么?
-04-07
JSawyer