Websockets 中的 \x00 和 \xff 是什么意思?

发布于 2024-10-15 04:31:02 字数 114 浏览 5 评论 0原文

为什么通过 websocket 的消息总是以 \x00 开头并以 \xff 结尾,如 \x00Your message\xff 中所示?

Why do messages going through websockets always start with \x00 and end with \xff, as in \x00Your message\xff?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

耳根太软 2024-10-22 04:31:02

这个文档可能会有所帮助......

摘自第1.2节: -

   Data is sent in the form of UTF-8 text.  Each frame of data starts
   with a 0x00 byte and ends with a 0xFF byte, with the UTF-8 text in
   between.

   The WebSocket protocol uses this framing so that specifications that
   use the WebSocket protocol can expose such connections using an
   event-based mechanism instead of requiring users of those
   specifications to implement buffering and piecing together of
   messages manually.

   To close the connection cleanly, a frame consisting of just a 0xFF
   byte followed by a 0x00 byte is sent from one peer to ask that the
   other peer close the connection.

   The protocol is designed to support other frame types in future.
   Instead of the 0x00 and 0xFF bytes, other bytes might in future be
   defined.  Frames denoted by bytes that do not have the high bit set
   (0x00 to 0x7F) are treated as a stream of bytes terminated by 0xFF.
   Frames denoted by bytes that have the high bit set (0x80 to 0xFF)
   have a leading length indicator, which is encoded as a series of
   7-bit bytes stored in octets with the 8th bit being set for all but
   the last byte.  The remainder of the frame is then as much data as
   was specified.  (The closing handshake contains no data and therefore
   has a length byte of 0x00.)

This documentation might help...

Excerpt from section 1.2:-

   Data is sent in the form of UTF-8 text.  Each frame of data starts
   with a 0x00 byte and ends with a 0xFF byte, with the UTF-8 text in
   between.

   The WebSocket protocol uses this framing so that specifications that
   use the WebSocket protocol can expose such connections using an
   event-based mechanism instead of requiring users of those
   specifications to implement buffering and piecing together of
   messages manually.

   To close the connection cleanly, a frame consisting of just a 0xFF
   byte followed by a 0x00 byte is sent from one peer to ask that the
   other peer close the connection.

   The protocol is designed to support other frame types in future.
   Instead of the 0x00 and 0xFF bytes, other bytes might in future be
   defined.  Frames denoted by bytes that do not have the high bit set
   (0x00 to 0x7F) are treated as a stream of bytes terminated by 0xFF.
   Frames denoted by bytes that have the high bit set (0x80 to 0xFF)
   have a leading length indicator, which is encoded as a series of
   7-bit bytes stored in octets with the 8th bit being set for all but
   the last byte.  The remainder of the frame is then as much data as
   was specified.  (The closing handshake contains no data and therefore
   has a length byte of 0x00.)
書生途 2024-10-22 04:31:02

工作规范已更改,不再使用 0x00 和 0xFF 作为开始和结束字节

http://tools.ietf.org/id/draft-ietf-hybi-thewebsocketprotocol-04.html

The working spec has changed and no longer uses 0x00 and 0xFF as start and end bytes

http://tools.ietf.org/id/draft-ietf-hybi-thewebsocketprotocol-04.html

傻比既视感 2024-10-22 04:31:02

我对此不是 100% 确定,但我的猜测是表示消息的开始和结束。由于 x00 是 0 的单字节表示,而 xFF 是 255 的单字节表示

I am not 100% sure about this but my guess would be to signify the start and end of the message. Since x00 is a single byte representation of 0 and xFF is a single byte representation of 255

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文