我试图通过TCP连接从Firefox OS发送一些数据。最初我开始用loginBytes
填充数据,这些数据可以帮助我登录ip
和port
指定的服务(数组大小为28字节),现在我&# 39;我试图发送一个空数组。在任何情况下结果都是相同的:在Firefox Web IDE的控制台日志中,我可以看到以下消息:uncaught exception: out of memory
。在我尝试用于调试的消息中只打印了"Started sending data"
。所以我得出结论,失败发生在执行send
命令期间。但它有什么问题呢?
(function() {
var sendButton = document.querySelector('#send');
var notes = document.querySelector('#notes');
var options = {binaryType: 'arraybuffer'};
var socket = navigator.mozTCPSocket.open(ip, port, options);
sendButton.addEventListener('click', function() {
var loginBytes = [];
var Int8View = new Uint8Array(loginBytes);
socket.ondata = function(event) {
console.log("Started receiving data");
console.log(event.data);
console.log("Received successfully");
}
socket.onerror = function(event) {
console.log("Everything is bad");
}
console.log("Started sending data");
socket.send(Int8View);
console.log("Sent successfully");
});
})();
答案 0 :(得分:0)
我认为
var Int8View = new Uint8Array(loginBytes)
需要更改为:
var Int8View = new Uint8Array(loginBytes).buffer
Uint8Array本身不会返回ArrayBuffer对象。