socket.io streaming binary data

自闭症网瘾萝莉.ら 提交于 2020-01-22 14:27:31

问题


I have just started using node.js, I'm running a node server with sockets.io and i need to send a buffer of bytes to the client.

I understand that this can be done by first translating the byte buffer to base64 and sending that, then translating it back on the client side. but i was wondering if there is a more elegant way of getting the byte stream to the client.


回答1:


Socket.IO 1.0 Now supports Binary data transfer. Please have a look here . You can use Blob, ArrayBuffer and File.




回答2:


https://github.com/binaryjs/binaryjs can be a solution. base 64 have ~30% of overhead size, so if you need to transfer large amount of data it will become inefficient.




回答3:


There is also socket.io-stream https://github.com/nkzawa/socket.io-stream




回答4:


It is little difficult to use binaryjs with socket.io. Try deliveryjs

https://github.com/liamks/Delivery.js

which provides the means of communication between clients and server via socket.io.

However this module also uses the base64 conversion, which is a drawback.



来源:https://stackoverflow.com/questions/12228274/socket-io-streaming-binary-data

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