"未捕获的异常:内存不足"在用于Firefox OS的TCP客户端中

时间:2015-12-03 08:28:19

标签: tcpclient firefox-os

我试图通过TCP连接从Firefox OS发送一些数据。最初我开始用loginBytes填充数据,这些数据可以帮助我登录ipport指定的服务(数组大小为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");                                   
    });
})();

1 个答案:

答案 0 :(得分:0)

我认为

var Int8View = new Uint8Array(loginBytes)

需要更改为:

var Int8View = new Uint8Array(loginBytes).buffer

Uint8Array本身不会返回ArrayBuffer对象。