TCP client in Firefox OS. No response from the server

霸气de小男生 提交于 2019-12-12 05:28:09

问题


I'm developing an app for Firefox OS which should communicate with the server via TCP connection. You can see the code below (the only difference is that I substituted actual ip address and port with variable names and excluded the content of loginButes (actually, there is exactly 24 bytes there)). The problem is that I can see only "Sent successfully" in console. So I don't obtain any response from the server at all. As far as I understand, there might be two possible reasons of this issue: either the data, I'm using in order to connect, is incorrect or the way, I'm trying to receive the response from the server, is wrong. Let's suppose that everything is fine with the data. Should my code receive a response or not? (i.e. should socket.ondata be executed if server sends me smth in response)

(function() {
    var options = {binaryType='arraybuffer'};    
    var socket = navigator.mozTCPSocket.open(ip, port, options);

    sendButton.addEventListener('click', function() {
        var loginButes = [];
        var Int8View = new Uint8Array(loginBytes);

        socket.ondata = function(event) {
            console.log(event.data);
            console.log("Received successfully");
        }
        socket.onerror = function(event) {
            console.log("Everything is bad");
        }

        socket.send(Int8View);
        console.log("Sent successfully");
    });
})();

P.S. Thanks to the @DavidHoldeman's answer, I got rid of the initial issue and came to another one. I get "uncaught exception: out of memory" when sending the data now. Could you please suggest what might be the reason of that error?


回答1:


The 'options' argument passed to mozTCPSocket.open should be an object:

var options = { binaryType: 'arraybuffer' };
var socket = navigator.mozTCPSocket.open(ip, port, options);

This tripped me up the first time too. Good luck and happy coding!



来源:https://stackoverflow.com/questions/33982752/tcp-client-in-firefox-os-no-response-from-the-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!