简体   繁体   English

为什么在 Web Sockets 中使用二进制数据?

[英]Why Use Binary Data in Web Sockets?

What's the purpose of using binary data for websockets.将二进制数据用于 websockets 的目的是什么。 Is it mainly for encryption purposes, or does it make anything faster or better than regular text?它主要用于加密目的,还是比普通文本更快或更好?

For example: https://github.com/websockets/ws例如: https : //github.com/websockets/ws

Shows how to send and receive binary data.显示如何发送和接收二进制数据。 But I'm not sure what I'd use that for.但我不确定我会用它做什么。

Binary vs text is not necessary a WebSocket-related issue.二进制与文本不是 WebSocket 相关问题所必需的。 It is a fundamental difference in data format for computing particularly for data transmission.这是用于计算的数据格式的根本区别,特别是对于数据传输。 Very roughly speaking, binary format is smaller, it is used for encryption (as you correctly point out), its use for compression of large data sets, its used for multimedia (images, sound) and generally faster to send over the wire.粗略地说,二进制格式较小,用于加密(正如您正确指出的那样),用于压缩大型数据集,用于多媒体(图像,声音)并且通常通过线路发送速度更快。 Binary is the natural language of the computer.二进制是计算机的自然语言。 Text is the natural language of humans.文本是人类的自然语言。 It typically is readable... as long as its translated... ;) Text is usually easier to deal with in programs and is usually easier to use as a data format within computer programs (since we're human).它通常是可读的......只要它被翻译...... ;) 文本通常在程序中更容易处理,并且通常更容易在计算机程序中用作数据格式(因为我们是人类)。

Which one you use is based on the requirements of your program, both functional and performance.您使用哪一种取决于您的程序要求,包括功能和性能。

WebSocket is just a means to send the data (in either text or binary) from once place to another using a web-friendly protocol. WebSocket 只是一种使用 Web 友好协议将数据(以文本或二进制形式)从一个地方发送到另一个地方的方法。

二进制数据可能是一个字节数组,javascript 将使用它在 html 5 canvas 元素上显示图片。

Binary is the most basic form of data.二进制是最基本的数据形式。 If your communication mechanism supports binary data, it supports all data without special treatment (encoding).如果您的通信机制支持二进制数据,则它支持所有数据,无需特殊处理(编码)。

For that reason, any communication mechanism that supports binary transmission would want to express that ability.出于这个原因,任何支持二进制传输的通信机制都希望表达这种能力。

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

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