Sending a Float32Array via socket.io

匆匆过客 提交于 2021-01-28 17:04:45

问题


I am currently stuck at sending a Float32Array via socket.io to another socket.

There is no real code to show, since I am only using socket.emit and socket.on.

On the other end of the socket the Float32Array remains as a Object. Here are to pictures from the Float32Array before emiting and the remains after emiting.

Before:

Remains:

If it is not possible to send the Float32Array to another socket, would it be possible to send a Blob to another socket?

Both sockets are Chrome clients. socket.emit emits to the server and the server emits to every client.


回答1:


Sending in the client:

var array = new Float32Array(...);
socket.emit('data', array.buffer);

Receiving in the client:

socket.on('data', function(data) {
  var array = new Float32Array(data);
  ...
});

I don't think you need to do anything special in the server, just pass along the data that you receive from the first client to the second client.



来源:https://stackoverflow.com/questions/31815262/sending-a-float32array-via-socket-io

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