简体   繁体   English

如何在没有库的情况下使用来自 node.js 的 websocket 正确发送二进制消息?

[英]How to properly send binary messages using websocket from node.js without libraries?

The fact is that I'm trying to implement the dependency free websocket server, I found a couple of articles on this topic in English.事实上,我正在尝试实现无依赖的 websocket 服务器,我发现了几篇关于这个主题的英文文章。 and Russian, but in both articles only processing of "short" text messages is considered, unfortunately nothing is said about binary ones.和俄语,但在这两篇文章中只考虑了“短”文本消息的处理,不幸的是,没有提到二进制消息。 And at the moment, apparently, I do not have enough qualifications to understand how to send binary messages (with text messages everything is ok, thanks to the articles I can both receive and send them without any problems).目前,显然,我没有足够的资格来理解如何发送二进制消息(通过文本消息一切正常,多亏了这些文章,我可以毫无问题地接收和发送它们)。 In this connection, I ask for help here.在这方面,我在这里寻求帮助。 If any of you can provide an example of how binary messages are sent, I would really appreciate it.如果你们中的任何一个人可以提供一个如何发送二进制消息的例子,我将非常感激。 Please do not post links to existing libraries implementing ws in node.js, I tried looking at their source.请不要发布指向在 node.js 中实现 ws 的现有库的链接,我尝试查看它们的源代码。

const secondByte = buffer.readUInt8(1); const secondByte = buffer.readUInt8(1); const isMasked = Boolean((secondByte >>> 7) & 0×1); const isMasked = Boolean((secondByte >>> 7) & 0×1);

One of the articles explaining how to work with this has an example above Can someone suggest, when the author of the article calculates whether the buffer is masked, it compares with the text opcode, right?其中一篇解释如何使用它的文章上面有一个例子有人可以建议,当文章作者计算缓冲区是否被屏蔽时,它会与文本操作码进行比较,对吗?

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

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