如何从Node.js socket.io服务器向浏览器客户端发送二进制数据? [英] How to send binary data from a Node.js socket.io server to a browser client?

查看:340
本文介绍了如何从Node.js socket.io服务器向浏览器客户端发送二进制数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在查看整个Socket.IO文档,但是,即使他们承诺它存在,我也找不到一个简单的,最简单的例子,说明如何在服务器/客户端之间发送二进制数据。 / p>

怎么做?

解决方案

事实上在文档。 Socket.io的当前文档在 Socket.emit 下说:


[...]将事件发送到由字符串名称标识的套接字。可以包含任何其他
参数。支持所有数据结构,包括Buffer [...]


因此,如果您可以发送缓冲区,则可以发送二进制数据。您所要做的就是将数据打包到缓冲区对象中。



您可能需要阅读 Socket.io二进制支持发送和接收二进制文件


I've been looking through the entire Socket.IO docs, but, even though they promise it is there, I can't find a simple, minimal example, of how one would send binary data between server/client.

How is it done?

解决方案

It is in fact in the documentation. The current documentation for Socket.io says under Socket.emit:

[...] Emits an event to the socket identified by the string name. Any other parameters can be included. All datastructures are supported, including Buffer [...]

So, if you can send a buffer, you can send binary data. All you have to do is to pack your data into a Buffer object.

You may want to read Socket.io Binary Support and Sending and Receiving Binary

这篇关于如何从Node.js socket.io服务器向浏览器客户端发送二进制数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆