• Thanks @ClearMemory041063 for giving attention to my problem, and for the codes to try. You are not testing them on an esp8266, are you ? The last code makes 11,5kb minified, it does not fit, it interrupt the transfer from the IDE. So I had to remove the connecting code and reduce the data to send to 3kb. I cannot send more at once without getting memory errors.

    Unfortunately, at the end, the result with ws is as slow as with http: 2.5sec for 3kb (see the code below). Maybe because ws server is built on top of an http server.

    var n = 5, chk=3*1024;
    var tdata=new Uint8Array(chk);
    var i;
    for(i=0;i<1024;i++){
      tdata[i]=0x30;
      tdata[i+1024]=0x31;
    //  tdata[i+1024*2]=0x32;
    //  tdata[i+1024*3]=0x33;
    //  tdata[i+1024*4]=0x34;
    }//next i
     
    var page = '<html><body><script>var ws;setTimeout(function(){';
    page += 'ws = new WebSocket("ws://" + location.host + "/my_websocket", "protocolOne");';
    page += 'var t=(new Date()).getTime();ws.onmessage = function (event) { console.log("t:",(new Date()).getTime()-t,"MSG:",event.data); };';
    page += 'setTimeout(function() { ws.send("Hello to Espruino!"); }, 1000);';
    page += '},1000);</script></body></html>';
    
    function onPageRequest(req, res) {
      res.writeHead(200, {'Content-Type': 'text/html'});
      res.end(page);
    }
    
    var server = require('ws').createServer(onPageRequest­);
    server.listen(80);
    server.on("websocket", function(ws) {
        ws.on('message',function(msg) { print("[WS] "+JSON.stringify(msg)); });
      var t=getTime();
      ws.send(E.toString(tdata));
      print("n=",n,"t:",(getTime()-t).toFixed(­3),"sec");
      var inter=setInterval(function(){
        var l=ws.socket.dSnd.length;
        print("t",getTime()-t,"l",l);  
        if(l===0) clearInterval(inter);
      },100);
     //   ws.send("Hello from Espruino!");
    });
    
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v95.155 Copyright 2017 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 4MB:512/512, manuf 0xef chip 0x4016
    >
    =undefined
    n= 5 t: 0.018 sec
    t 0.12109500000 l 2984
    t 0.22103200000 l 2984
    t 0.32097500000 l 2716
    t 0.420522 l 2716
    t 0.52113300000 l 2448
    t 0.62102500000 l 2448
    t 0.72063500000 l 2180
    t 0.82108700000 l 2180
    t 0.921061 l 1912
    [WS] "Hello to Espruino!"
    t 1.020693 l 1644
    t 1.12096200000 l 1644
    t 1.22103700000 l 1376
    t 1.32081700000 l 1376
    t 1.42095800000 l 1108
    t 1.52093400000 l 1108
    t 1.62055600000 l 840
    t 1.72074900000 l 840
    t 1.82093100000 l 840
    t 1.92100099999 l 572
    t 2.020918 l 572
    t 2.12098700000 l 304
    t 2.220733 l 304
    t 2.320561 l 36
    t 2.42057400000 l 36
    t 2.52083200000 l 0
    
About

Avatar for Polypod @Polypod started