@Gordon
Your code enhance the performance of 'ws' aobut five times.
in the 'ws' codes:
var mask = [];
for (var ix = 0; ix < 4; ix++){
var rnd = Math.floor( Math.random() * 255 );
mask[ix] = rnd;
//masked += strChr(rnd);
}
var masked = new Uint32Array(1+((msg.length+3)>>2));
var m8 = new Uint8Array(masked.buffer, 0, (4 + msg.length));
m8.set(mask,0);
m8.set(msg,4);
var m = masked[0];
for (var i=1;i<masked.length;i++) {
masked[i]^=m;
}
// E.mapInPlace could be even faster here
this.socket.write(m8);
result:
connected? err= null info= {
"ip": "192.168.1.30",
"netmask": "255.255.255.0",
"gw": "192.168.1.1",
"mac": "30:ae:a4:03:96:a8"
}
connected
Packet NO.: 1, time used: 0.122781s
Packet NO.: 2, time used: 0.130532s
Packet NO.: 3, time used: 0.130694s
Packet NO.: 4, time used: 0.121443s
Packet NO.: 5, time used: 0.122264s
Packet NO.: 6, time used: 0.128198s
Packet NO.: 7, time used: 0.118977s
Packet NO.: 8, time used: 0.128156s
Packet NO.: 9, time used: 0.126372s
Packet NO.: 10, time used: 0.128605s
Packet NO.: 11, time used: 0.123227s
Packet NO.: 12, time used: 0.129712s
Packet NO.: 13, time used: 0.122637s
Packet NO.: 14, time used: 0.128667s
Packet NO.: 15, time used: 0.123411s
Packet NO.: 16, time used: 0.122551s
Packet NO.: 17, time used: 0.130601s
Packet NO.: 18, time used: 0.124756s
Packet NO.: 19, time used: 0.130782s
Packet NO.: 20, time used: 0.125312s
Packet NO.: 21, time used: 0.125905s
Packet NO.: 22, time used: 0.142719s
Packet NO.: 23, time used: 0.127608s
Packet NO.: 24, time used: 0.126586s
Packet NO.: 25, time used: 0.127527s
Packet NO.: 26, time used: 0.131625s
Packet NO.: 27, time used: 0.134015s
Packet NO.: 28, time used: 0.13283s
Packet NO.: 29, time used: 0.132503s
Packet NO.: 30, time used: 0.125586s
Packet NO.: 31, time used: 0.134384s
Packet NO.: 32, time used: 0.133459s
Packet NO.: 33, time used: 0.128191s
Packet NO.: 34, time used: 0.12743s
Packet NO.: 35, time used: 0.133592s
Packet NO.: 36, time used: 0.134646s
Packet NO.: 37, time used: 0.132336s
Packet NO.: 38, time used: 0.128793s
Packet NO.: 39, time used: 0.137423s
Packet NO.: 40, time used: 0.128829s
Packet NO.: 41, time used: 0.127535s
Packet NO.: 42, time used: 0.135589s
Packet NO.: 43, time used: 0.129962s
Packet NO.: 44, time used: 0.135888s
Packet NO.: 45, time used: 0.127731s
Packet NO.: 46, time used: 0.13064s
Packet NO.: 47, time used: 0.135926s
Packet NO.: 48, time used: 0.135231s
Packet NO.: 49, time used: 0.135276s
Packet NO.: 50, time used: 0.137039s
Packet NO.: 51, time used: 0.136779s
Packet NO.: 52, time used: 0.132308s
Packet NO.: 53, time used: 0.130578s
Packet NO.: 54, time used: 0.130833s
Packet NO.: 55, time used: 0.145101s
Packet NO.: 56, time used: 0.134404s
Packet NO.: 57, time used: 0.138408s
Packet NO.: 58, time used: 0.132389s
Packet NO.: 59, time used: 0.146416s
Packet NO.: 60, time used: 0.136446s
ERROR: Out of Memory!
ERROR: Ctrl-C while processing interval - removing it.
Execution Interrupted during event processing.
at line 1 col 461
...[f]^=i;this.socket.write(c),e=undefined,b=undefined,c=undefi...
^
in function "send" called from line 2 col 23
ws.send(packet);
^
in function called from system
What strange is that after 60 packets are transfered, the program throws " out of memory " error, every time.
AND , when the server receives the second packet, it crashed every time.
Server is listening on port 5004
a client connected
isTalking : false
<Buffer 81 fe>
received data: 1,230
<Buffer 35 38>
events.js:160
throw er; // Unhandled 'error' event
^
Error: invalid opcode: 5
The first two bytes of the first packet is correct, and that of the second packet is wrong. The first tow bytes of the second(and every frame/packet) should be , but they are now.
The error is throwed by the codes in Receiver.js of ws module on nodejs
if ((buf[0] & 0x30) !== 0x00) {
this.error(new Error('RSV2 and RSV3 must be clear'), 1002);
return;
}
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
@Gordon
Your code enhance the performance of 'ws' aobut five times.
in the 'ws' codes:
result:
What strange is that after 60 packets are transfered, the program throws " out of memory " error, every time.
AND , when the server receives the second packet, it crashed every time.
The first two bytes of the first packet is correct, and that of the second packet is wrong. The first tow bytes of the second(and every frame/packet) should be , but they are now.
The error is throwed by the codes in Receiver.js of ws module on nodejs
I'll try to find the problem.