简体   繁体   English

如何从WebSocket的二进制数据流填充数组

[英]How do I fill an array with binary data streaming from websocket

I got a continuous stream of byte data receiving from websocket. 我从websocket得到了连续的字节数据流。 When I view the data with this function: 当我使用此功能查看数据时:

document.getElementById('log').innerHTML = document.getElementById('log').innerHTML + msg + "<br />";

It would look like this: 它看起来像这样:

-0.00005645785104823496
0.00000906544783255643
-0.001234972515485563
0.00000008534781277461
.
.
.

I want to fill it in an array that would look like 我想将其填充到一个看起来像的数组中

var inp = new Array(event.data)
  , arr = new Float32Array()
  ;
for(var i = 0;i <arr.length; i++) {
    arr[i] = inp[i];
}

How do I fill the inp[i] array with data receiving from websocket. 如何用从websocket接收的数据填充inp [i]数组。

Thanks 谢谢

I found the answer, it was: 我找到了答案,它是:

shifted = inp.shift();

Thank you for any help. 感谢您的任何帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM