yEnc 用于二进制 websocket 数据
目前只能通过 websocket 传输原始文本数据,但是这样传输数字不是很浪费吗?
我读到一些应用程序使用 base64 编码,但我也记得这会给您的数据增加相当多的开销。
所以我的问题是:
- 使用 yEncoding 比使用 base64 更好吗?
- 我应该为常规号码而烦恼他们中的任何一个吗?
Currently you can only transfer raw text data over websockets, but isn't it wasteful to transfer numbers over like this?
I read some applications use base64 encoding, but I also remember that adds quite a lot of overhead to your data.
So my questions:
- Is it better to use yEncoding over base64?
- Should I bother with either of them for regular numbers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要过早优化。除非您要传输大量数字(即每秒许多 MB),否则只需将数字作为字符串发送即可。进行特殊编码会节省带宽,但会消耗 CPU(两端)。
在 noVNC 中,我使用 base64 来通过 WebSocket 传输二进制数据。这使原始二进制文件的带宽增加了 33%(不幸的是,在 API 公开二进制接口之前这是必需的),但我仍然获得了良好的性能,并且每秒传输许多 MB。因此,道德是,除非有充分的理由,否则不要进行优化。首先采用简单直接且设计良好的解决方案,然后在有真正理由时进行优化。
Do not optimize prematurely. Unless you are transferring a LOT of numbers (i.e. many MB per second), just send your numbers as strings. Doing a special encoding will save you bandwidth at the cost of CPU (on both ends).
In noVNC I use base64 to be able to transfer binary data over WebSockets. This increases the bandwidth over raw binary by 33% (unfortunately, necessary until the API exposes a binary interface), but I still get good performance and I am transferring many MB per second. So the moral is, don't optimize until you have a good reason to do so. Go with the simple straight-forward and well designed solution first and then optimize when you have a real reason to do so.