已解答:Websockets 消息类型:文本与二进制
注意:在撰写本文之前,我已经阅读了一些提示的建议线程,但是我没有确定要寻找的答案。
我有一个关于Websockets并在发送二进制通信时建立数据类型的快速问题,并了解收到哪种类型?
例如,如果我的对象具有以下架构{字符串,字符串,int,int,dateTime},则如何使用WebSockets中的二进制对象发送此对象?我还能确保他们知道他们收到的信息的模式,以便可以正确解析它?
似乎像Signalr这样的图书馆抽象了,但我很想知道它是如何在引擎盖下工作的。谢谢
Note: I have had a read of a few suggested threads by the prompt before writing this, but I didn't ascertain the answer I'm looking for.
I have a quick question about websockets and establishing the type of the data when sending communications in binary and understanding what type it is when received?
For example, if I have an object which has the following schema {string, string, int, int, DateTime}, how could I send this object in binary using websockets? How could I also ensure they know the schema of the message they receive so they can properly parse it?
It seems libraries like SignalR abstract this away but I'd love to know how it works under the hood. Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WebSocket 协议允许每条消息发送不同的消息格式。它可以是 UTF8 文本或二进制。使用这些 API 的应用程序可以决定发送什么内容,而消费者可以读取消息并判断它是二进制还是 UTF8 编码文本。现在这只是高级协议,但应用程序还需要以序列化格式包装消息(可以是原始文本、JSON 任何可以以字节序列编码的内容)。这就是像 SignalR 这样的库发挥其魔力的地方。
SignalR 有 2 个版本:
The WebSocket protocol allows sending different message formats per message. It can be UTF8 text or binary. The application using these APIs get to decide what to send, and the consumer can read the message and tell if it's binary or UTF8 encoded text. Now that's just the high level protocol but the application also needs to wrap messages in a serialization format (could be raw text, JSON anything that can be encoded in a sequence of bytes). This is where libraries like SignalR do their magic.
There are 2 versions of SignalR: